Configuring php mail() per domain

17,596

From the PHP manual for mail():

Note: When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.

Like most php.ini settings this can overridden in the vhost config on Apache or via .htaccess or it can be set in the script (optionaly using auto_prepend) and since 5.3.0 via .user.ini files. But rather than explicitly setting the From, Reply-To and Return-path headers, it's simpler to just specify the recipient when the 'sendmail' program is invoked to process the message.

Assuming exim uses the standard flags on the commandline for its sendmail cli:

in php.ini:

sendmail_path = "/usr/sbin/sendmail [email protected] -t -i"

In httpd.conf

php_admin_value sendmail_path "/usr/sbin/sendmail [email protected] -t -i"

In .htaccess.conf

php_value sendmail_path "/usr/sbin/sendmail [email protected] -t -i"

(note your sendmail path may be different from that shown)

C.

Share:
17,596

Related videos on Youtube

Admin
Author by

Admin

Updated on September 17, 2022

Comments

  • Admin
    Admin over 1 year

    I have about 6 sites on my dedicated server (running centos5), and all emails sent using php's mail function are sent by [email protected] e.g. "Received: from nobody by servername.hostname.com with local (Exim 4.69)". Is there any way to change this to show the appropriate domain?

    • Admin
      Admin almost 14 years
      You could use header rewriting but that will not work as all mail is being submitted by the same user (nobody)
  • Farkie
    Farkie over 8 years
    This is incorrect - you can't set sendmail_path per domain, it's systemwide: php.net/manual/en/mail.configuration.php
  • Thomas Szteliga
    Thomas Szteliga over 6 years
    @Farkie are you sure? PHP_INI_SYSTEM Entry can be set in php.ini or httpd.conf <php.net/manual/en/configuration.changes.modes.php>. For example default DirectAdmin vhost templates set the from field via sendmail_path in each vhost section of httpd.conf.
  • reinierpost
    reinierpost about 5 years
    That means it can't be set in .htaccess, which isn't named .htaccess.conf by the way.