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.
php.ini

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
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 myemail@somewhere.com

 

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

About these ads

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

  1. Pingback: The Dev Pages » Blog Archive » Using the mail() function in php with postfix on linux

      1. ice

        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: me@hushmail.me‘; But once I change it to a different address, such as me@gmail.com, (ie., ‘From: me@gmail.com‘;) 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 me@hushmai.me.

        Like

      2. ykyuen Post author

        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.

        Like

  2. Edvilson

    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

    Like

    Reply
  3. Pingback: How To: Nginx, PHP-FPM, MySQL, phpMyAdmin, Postfix on Ubuntu | Deadly Technology

  4. Nic Lyon

    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.

    Like

    Reply
    1. Nic Lyon

      The error log
      Feb 11 07:46:31 h4x0r-Linux postfix/smtp[13557]: connect to alt1.gmail-smtp-in.l.google.com[74.125.137.27]:25: Connection timed out
      Feb 11 07:46:31 h4x0r-Linux postfix/smtp[13557]: connect to alt1.gmail-smtp-in.l.google.com[2607:f8b0:400e:c01::1a]:25: Network is unreachable
      Feb 11 07:46:31 h4x0r-Linux postfix/smtp[13557]: connect to alt2.gmail-smtp-in.l.google.com[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,

      Like

      Reply
  5. Pingback: Установка и настройка сервера на linux | схблог

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s