Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am setting up a VPS on linode but I can't seem to setup a mail sending program like sendmail so that I can send emails through PHP.

I am stuck at the very first step of changing the hostname. I changed the entries under /etc/hostname and /etc/hosts but when I even reboot the VPS, then hostname -f shows hostname: Name or service not known

What's wrong? And any good tutorial for setting things up?

I am using nginx, if that somehow matters in any case.

Content of /etc/hosts localhost

# The following lines are desirable for IPv6 capable hosts
::1 ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts

Content of /etc/hostname

And which hostname returns /bin/hostname

share|improve this question
What did you put in /etc/hosts? – Bart De Vos May 12 '11 at 12:21
What does it tell you when you do ´which hostname´ ? – Matthieu May 12 '11 at 12:23
@TiZon @Matthieu I have added the info in the question, please take a look – Ashfame May 12 '11 at 12:33
up vote 2 down vote accepted

Edit /etc/hosts like this:      mail localhost      mail

add this to /etc/resolv.conf


Then, reboot and try with /bin/hostname --fqdn

To set-up email, this is what I would do:

sudo apt-get dist-upgrade -y && sudo apt-get update -y
sudo reboot
sudo apt-get install postfix mailutils -y
sudo postconf -e "mydestination =,, localhost.localdomain, localhost"
sudo postconf -e "mynetworks ="
sudo postconf -e "inet_interfaces = all"
sudo  /etc/init.d/postfix restart
share|improve this answer
@TiZon Thanks! That did it. Any pointers for a simple tutorial for setting things up so that I can send mail. Which one do you suggest out of sendmail and others? – Ashfame May 12 '11 at 12:46
@Ashfame I have edited my answer with some installation-instructions. I would go with sendmail. – Bart De Vos May 12 '11 at 12:53
@TiZon Thanks a lot so far! I think its almost ready. I managed to get to the same point using exim and your instructions (tried yours afterwards, after removing exim). If I send a test mail using echo "This is a test." | mail -s Testing, I get the email, but if I use PHP mail function, it return boolean false. Do I need to make changes in some PHP config file too? Or that should be a different question possibly out of scope of serverfault? – Ashfame May 12 '11 at 13:15
I think PHP uses sendmail, Can you send an email via sendmail? – Bart De Vos May 12 '11 at 13:23
@TiZon Yeah! I can. I tried using the code on this page – Ashfame May 12 '11 at 18:15

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.