Request-Path with PHP

201 Views Asked by At

I am trying to use the Request-Path header with the PHP mail() function, but it doesn't work. The Return-Path keeps on being changed to the From header.

From googling, I found useful tips, but none of them worked for me, though I learned many things.

Here is the very simple code I am using :

$headers ='From: "Marty"<[email protected]>'."\r\n";
//$headers .='Return-Path: [email protected]'."\r\n";
$headers .='Reply-To: [email protected]'."\r\n";
$headers .='Content-Type: text/plain; charset="iso-8859-1"'."\r\n";
$headers .='Content-Transfer-Encoding: 8bit';

$returnPath = '[email protected]';

if (mail('[email protected]', 'My subject', 'My body', $headers, $returnPath)) {
    echo 'Message sent';
} else {
    echo 'Message not sent';
}

And here is what I tried so far :

  • with \n and \r\n as line feeds in the header
  • with the Return-Path in the $header string
  • with the Return-Path as the 5th parameter of the mail() function
  • with Return-Path both in $headers and in $returnPath
  • with and without a space in the $returnPath variable after -f
  • with -r in the $returnPath, with and without a space, with and without -f

As I have read, there could be some problems with the exim configuration which replaces the Return-Path by the PHP user. But this is not the case here, as it is replaced by the From header.

I am nearly sure this is a configuration thing, as this code is very simple, but I cannot find anything useful...

Thank you for your help !

EDIT : We don't use Exim on our Linux server, so the problem does not come from there. I tried to achieve the same goal with SwiftMailer, but to no avail. The Return-Path is still ignored....

require('swift/lib/swift_required.php');

$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
->setUsername('[email protected]')
->setPassword('myPassword');

$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setTo(array('[email protected]'))
->setFrom(array('[email protected]' => 'Myself'))
->setReturnPath('[email protected]')
->setBody('Here is the message itself')
;

// Send the message
$result = $mailer->send($message);

This is directly taken from SwiftMailer example.

0

There are 0 best solutions below