phpemailreturn-path

PHP Mail Return-Path not bouncing back


I'm trying to test if the return-path will bounce back on my gmail, but not.

I'm testing to send it to my email (enalds@gmail.com): it works!
And send to unknown email (gifjgogsdkg@fafasfsa.com): it didn't bounce back.

Here's my code

<?php
$message = '
    <html>
    <head>
        <title>Sample Email</title>
    </head>
    <body>
        Sample Email
        <br /><br />
        <a href="http://asd.com/unsubscribe?email=sender_name@yahoo.com">Click here to Unsubscribe</a>
    </body>
    </html>
';

$sender = "enalds@gmail.com";
$email_address = "sender_name@yahoo.com";
$subject = "Testing Email";
$template_name = "Sample Email";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Return-Path: enalds@gmail.com' . "\r\n";
$headers .= 'From: '.$sender.'' . "\r\n";

if(mail($email_address, $subject, $message, $headers, '-fenalds@gmail.com'))
    echo "{$i}. {$email_address} - <span style='color:green'>Successfully</span> Sent [{$template_name}]<br />";
else
    echo "{$i}. {$email_address} - <span style='color:green'>Unsuccessfully</span> Sent [{$template_name}]<br />";

Solution

  • You have two solutions to this issue: First one is leave blank in the php.ini configuration file the "sendmail_from" variable. This way you could add the additional parameters in the mail function like you have in your code.

    The second approach, is set "sendmail_from" in php.ini if you want to have always the same "Return-Path" for every email.