Configure Postfix/Sendmail for PHP mail() in Ubuntu

Actually configure Postfix or Sendmail for PHP mail() is the same. Both of them run the /usr/sbin/sendmail binary. It is quite confusing if we just look at the name of the binary but this is what Postfix did.

For more information, take a look at the Postfix Manual – sendmail.

For the PHP setting, open the /etc/php5/apache2/php.ini and configure the sendmail_path.

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
sendmail_path = "/usr/sbin/sendmail -t -i"


Save the file and restart the Apache server.

Try testing the PHP mail() function by the following command. Thanks amitbhatia1. =)

echo testing | mail -s Bla


If you need to send with attachment. you can refer to this post.
PHP – Send Attachment with PHP mail()

Done =)

Reference: Using the mail() function in php with postfix on linux


35 thoughts on “Configure Postfix/Sendmail for PHP mail() in Ubuntu”

      1. I didn’t set up the relay, because I hate gmail and want to close my account. I uninstalled postfix completely and installed it again and configed php.ini. Now mail() function is working. I have a question though.

        It works with $headers = ‘From:‘; But once I change it to a different address, such as, (ie., ‘From:‘;) the mail doesn’t get sent. In the mail.log file I see “Sender address rejected: Domain not found (in reply to MAIL FROM command)).” How can I fix this problem? When I save up enough money I want to build my own website, and I want to use the email address of my site to send and receive mails instead of


      2. i am sorry that i couldn’t help.

        actually some hosting providers have email service and what you need to do is just setting up the domain for the email service. i think maybe you can seek help from you web hosting service provider.


  1. I made a simple php script to test and is giving this error on my server
    server name: Demeter
    OS: Linux RedHat

    installed: apache + php + Sendmail

    sendmail works mada normal email is ok
    the problem is to have php that will not and this error:
    n 25 12:20:09 demeter sendmail[13202]: NOQUEUE: SYSERR(apache): can not chdir(/var/spool/clientmqueue/): Permission denied


  2. I can’t seem to get it to work, I just want to send mail, my server has internet access but my site is lan only as my isp blocks port-forwarding, but I don’t think that sould matter much to send mail any help appriciated.


    1. The error log
      Feb 11 07:46:31 h4x0r-Linux postfix/smtp[13557]: connect to[]:25: Connection timed out
      Feb 11 07:46:31 h4x0r-Linux postfix/smtp[13557]: connect to[2607:f8b0:400e:c01::1a]:25: Network is unreachable
      Feb 11 07:46:31 h4x0r-Linux postfix/smtp[13557]: connect to[2607:f8b0:4002:c04::1a]:25: Network is unreachable
      Feb 11 07:46:32 h4x0r-Linux postfix/smtp[13557]: 821ADAB1BA: to=, relay=none, delay=21372, delays=21311/0.08/60/0,


  3. It’s not working for me either.
    Using mail to send like in you example, I only receive a waring message.

    WARNING: gnome-keyring:: couldn’t connect to: /tmp/keyring-rgI6w9/pkcs11: file or directory not found

    but I don’t think that’s the problem.

    My mail.log file:

    Sep  9 11:05:50 caco-laptop postfix/pickup[27589]: 8B219E0F57: uid=1000 from=
    Sep  9 11:05:50 caco-laptop postfix/cleanup[28075]: 8B219E0F57: message-id=
    Sep  9 11:05:50 caco-laptop postfix/qmgr[27590]: 8B219E0F57: from=, size=325, nrcpt=1 (queue active)
    Sep  9 11:05:50 caco-laptop postfix/smtp[28077]: connect to[2800:3f0:4003:c00::6c]:587: Network is unreachable
    Sep  9 11:05:51 caco-laptop postfix/smtp[28077]: 8B219E0F57: to=,[]:587, delay=1.1, delays=0.14/0.02/0.71/0.2, dsn=5.7.0, status=bounced (host[] said: 530 5.7.0 Must issue a STARTTLS command first. z32sm9888357qgd.40 - gsmtp (in reply to MAIL FROM command))
    Sep  9 11:05:51 caco-laptop postfix/cleanup[28075]: C9DBEE0FBA: message-id=
    Sep  9 11:05:51 caco-laptop postfix/qmgr[27590]: C9DBEE0FBA: from=, size=2211, nrcpt=1 (queue active)
    Sep  9 11:05:51 caco-laptop postfix/bounce[28078]: 8B219E0F57: sender non-delivery notification: C9DBEE0FBA
    Sep  9 11:05:51 caco-laptop postfix/qmgr[27590]: 8B219E0F57: removed
    Sep  9 11:05:52 caco-laptop postfix/smtp[28077]: C9DBEE0FBA: to=,[]:587, delay=0.96, delays=0.09/0/0.67/0.2, dsn=5.7.0, status=bounced (host[] said: 530 5.7.0 Must issue a STARTTLS command first. l7sm10385441qaf.16 - gsmtp (in reply to MAIL FROM command))
    Sep  9 11:05:53 caco-laptop postfix/qmgr[27590]: C9DBEE0FBA: removed

    If you can help me?


  4. Hey Hi,
    postfix mail is working from past few years and suddenly it get stopped. dont know why.i tried to reinstall it. now i can able to send mails over command. But not with php code. but i did try to add this line to php.ini file.(sendmail_path = “/usr/sbin/sendmail -t -i”) and restart the postfix service. Here is the error log. please check and suggest.

    Jun 25 07:21:53 j78921 postfix/sendmail[29750]: fatal: Recipient addresses must be specified on the command line or via the -t option


  5. I had removed “sendmail” What worked for me was adding “.postfix” to the path. “sendmail_path = “/usr/sbin/sendmail.postfix -t -i”

    Liked by 1 person

  6. I am looking for a solution to a similar problem for the “Windows host – Debian Virtualbox” bundle.
    Unfortunately your solution did not work. Perhaps this is due to the old age of the post.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.