Applicable to:
- Plesk for Linux
- Plesk for Windows
Question
What is the default Return-Path
in PHP mail() scripts?
How to specify the exact default Return-Path
for PHP mail() scripts in Plesk?
Answer
By default, the system user assigned to the domain that is executing the script is used in the return path.
The functionality of changing this setting via Plesk UI is yet to be implemented. You may vote for such a possible feature on the UserVoice portal.
The top-ranked suggestions are likely to be included in the next versions of Plesk.
Some possible workarounds can be applied here:
CONFIG_TEXT: <?php
$to = "someuser@example.com";
$subject = "Test email";
$txt = "Hello world!";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: testuser@example.com' . "\r\n";
$headers .= 'Return-Path: testuser@example.com' . "\r\n";
mail($to,$subject,$txt,$headers, "-f testuser@example.com");
?>
-
Go to Domains > example.com > PHP Settings > Additional directives
-
Add a directive like the following:
CONFIG_TEXT: sendmail_path = "/usr/sbin/sendmail -t -i -f jdoe@example.com"
-
Go to Tools & Settings > PHP Settings > PHP x.x > php.ini
-
Change the
sendmail_from
parameter to required mailbox:CONFIG_TEXT: sendmail_from = jdoe@example.com
Comments
5 comments
I am using Plesk 12.5 with qmail.
Plesk's habit of setting the Return-Path address to the Plesk customer addres, rather than just leaving it the same as From address, breaks DMARC checks.
changing sendmail_from or sendmail_path in php.ini, using the 4th parameter in php mail() does not work. Banged my head on this for quite some time by listening to articles like this from Plesk.
Plesk still overrides the Return Path
Here is a solution to remove Plesk's setting of the Return Path completely and let the Return Path = From email address.
# cd /var/qmail/bin
# cp sendmail sendmail-plesk
# vi sendmail-modified
[PHP]
#!/bin/bash
sendmail="/var/qmail/bin/sendmail-plesk"
newargs=""
flag=0
# loop through command line arguements
for var in "$@"
do
# if the flag is set
if [ $flag = 1 ]
then
# don't add the from email address
flag=0
continue
fi
# if we find a -f tag that sets Return-Path
if [ $var = "-f" ]
then
# don't add the -f parameter
flag=1
continue
fi
# if we got here, its a command line parameter we don't want to skip
newargs="$newargs $var"
done
# send the stdin and new args to sendmail-plesk
cat | $sendmail $newargs
[/PHP]
# chmod 750 sendmail-modified
# chown root.qmail sendmail-modified
# rm sendmail
# ln -s sendmail-modified sendmail
Hello, Mike K!
Thank you very much for your continuous efforts!
We really appreciate you sharing the knowledge with us.
You can also set this value via PHP or .htaccess: https://alephnull.uk/correctly-set-return-path-send-email-php
Hello @Bernhard,
Thank you for the provided solution!
Others can find it useful
Hello, is it possible to use a variable for the email address?
If setting the email "For all domains on one PHP version" the email address would differ for each domain.
How can I set the email address to match the domain?
I see the php.ini says "For Win32 only"
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = me@example.com
For Linux, do we set the email here as well?
Or below? And if so, what should the sendmail_path = ?
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
;sendmail_path =
Please sign in to leave a comment.