PHP Mail(): Setting Return Path Fails Mail Sending

1.3k Views Asked by At

I am sending email using PHP's mail() function. However, when I set the ReturnPath header like '[email protected]', however the email fails with the return path 5th parameter but when not used, [email protected] return path is added. Is this an error and how do we get around to using specific return path.

Kind regards,

Khuram

1

There are 1 best solutions below

0
On

Assuming you're using Sendmail with root access to the server:

I've tested the result on my server where Sendmail is basically in it's factory configuration:

mail($email, $subject, $message, $headers, '-freturn@address');

When using -f, Sendmail must know that you are a trusted user. You must add the server user to /etc/mail/trusted-users. For example, if the web server user is apache or www-data, you must put that into the trusted-users file.

Once you've done this, you probably have to enable the feature. Edit /etc/mail/submit.mc and add the following line properly:

FEATURE('use_ct_file')dnl

Once you're done service sendmail restart should do the job.