how to check for email bounce using mail() function

the mail() function

Moderators: macek, egami, gesf

sanv
New php-forum User
New php-forum User
Posts: 3
Joined: Thu Jan 05, 2012 3:25 am

how to check for email bounce using mail() function

Postby sanv » Sat Jan 07, 2012 12:46 am

Hi,
I need to check is the mail is sent and successfully deliver to the recipient email.
here is the code :

if(mail($to, $subject, $message, $headers, '-f ' . $return_path))
{echo "Sent"; }else {echo "Not Sent";}

Please help me, its urgent.

Thanks,
sanv

TheProdigyGuy
New php-forum User
New php-forum User
Posts: 215
Joined: Wed Dec 07, 2011 5:25 pm

Re: how to check for email bounce using mail() function

Postby TheProdigyGuy » Tue Jan 10, 2012 3:37 pm

from php.net notes about PHP mail() function:

Code: Select all

Return Values
Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.


IMHO theris no proper way directly using PHP to check is that $to address exist and your mail delivery was successfull.
Generally when using bounce way right way to check is it accepted by remote server it is check your mailbox.
If that $to (mail addr) is not exist on remote mail server on that remote mail server will automatically reply to you:
Can't deliver your msg.bla bla bla + a lot of tonnes server info))

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: how to check for email bounce using mail() function

Postby egami » Tue Jan 10, 2012 5:39 pm

This is the reason why you will often see

if (mail($to,$subject,$message,$headers)) {
// This is where you would write success code, or call some kind of success function...
} else {
// This is where the mail function fails, and you should/could call some kind of failed function or something
}


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest