Mail

How to config default Return-Path in php mail

Original illustration: email php — image file missing from the original dataset

If some mail servers reject messages sent by a PHP script with the following error:

(host ezylinux.com[74.xx.xxx.xxx] said: 550-Verification failed for 550-The mail server could not deliver mail to [email protected]. The account or domain may not exist, they may be blacklisted, or missing the proper dns entries. 550 Sender verify failed (in reply to RCPT TO command))

This happens because “Return-path” is missing from the mail header. Some mail servers enforce this strictly and reject email from our system. To fix it, specify “Return-path” in the mail header. There are three ways:

  • Solution 1: mail() function Add -f to the fifth argument of the mail function, as shown. mail($toEmailAddress,$subject,$message,$headers,"-f [email protected]");
  • Solution 2: php.ini Edit php.ini and specify a default “Return-path” by adding -f to sendmail_path, as shown. sendmail_path = /usr/sbin/sendmail -t -i -f [email protected]
  • Solution 3: Apache vhost Set a PHP value for each Virtual Host by adding php_admin_value as shown below. php_admin_value sendmail_path "/usr/sbin/sendmail -t -i -f [email protected]"

*In these examples, the “Return-path” email address is [email protected]. Ref: How to add default Return-path in php mail

EOF.← Back to articles