How to set a custom Return-Path when sending emails using Mail::factory('smtp',

2.3k Views Asked by At

I'm trying to send emails that will bounce to an address specified by me, different from the address it's sent from.

the code i'm using to send the emails is

$headers = array (
    'From' => $emailAdr
    'To' => $emailDest,
    'Subject' => $subject,
);                                      
$hdrs = $mime->headers($headers);

$smtp = Mail::factory('smtp',
        array ('host' => 'ssl://'.$emailServer,
               'auth' => true,
               'port' => '465',
               'username' => $emailUser,
               'password' => $emailPass));

$mail = $smtp->send($emailDest, $hdrs, $body);

I searched all over the internet for a solution to this.

1

There are 1 best solutions below

2
On

Try this:

$headers = array (
    'From' => $emailAdr
    'To' => $emailDest,
    'Subject' => $subject,
    'Return-path' => '[email protected]',
); 

But, different mail servers translate return path by their own rules (it's just will use From, Reply-to or X-Return-Path etc