Configure sendmail on CentOS to allow sending of email from localhost

For some of my Drupal sites and PHP scripts (and shell scripts) that I run on a VPS I manage, I need to simply be able to send outgoing emails from arbitrary email addresses. I could go into all the details of DNS SPF records and MX records here, but that's something you'll need to research on your own. This post simply shows how to install and configure sendmail on a CentOS box to just allow outgoing mail from php's mail() function, the mail command line utility, etc., and only from localhost (

First, install sendmail with $ sudo yum install sendmail sendmail-cf.

Then, configure sendmail by editing the file /etc/mail/ (don't edit the file - we'll auto-generate that after setting things correctly in

  • Configure DAEMON_OPTIONS to only allow sending from localhost/smtp: DAEMON_OPTIONS(`Port=smtp,Addr=, Name=MTA')dnl
  • Set the LOCAL_DOMAIN option to your hostname: LOCAL_DOMAIN(`')dnl

Now, to update sendmail's configuration, enter $ sudo make -C /etc/mail, and then restart sendmail with $ sudo service sendmail restart.

You'll also want to make sure your hostname is set correctly (this will be the default from address domain); check it by entering $ hostname... if it's incorrect, you can set it explicitly in /etc/sysconfig/network as the HOSTNAME variable. You might also want to add your hostname to /etc/hosts as the first result for

(This guide assumes you're using RHEL or CentOS/Fedora...).


thnx, simple and useful. this helped me seting up a development lamp stack!

Thank you this was straight forward and helped.

Thank you, Its working.
It is very easy & simple to understand/implement.

Thank you for this tuto.
I had tryed before SendMail, I had to do "alternatives --config mta" and choose Ssmtp service to use it (Centos7).

Thanks! You make my day!

Thanks, this put me on the right track.
In the end, this post also helped me with this issue: