How to check if a mail has bounced in PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
siji86
Forum Commoner
Posts: 30
Joined: Fri Mar 26, 2010 6:15 am

How to check if a mail has bounced in PHP

Post by siji86 »

Hi,
I am working on an application which sends email to a couple of users. But the application also needs to know about the emails that get bounced. I searched on google and go to know that you need to define a return path. Here is the code

Code: Select all

$user_id=13;
$return_path = "user-".((int)$user_id)."-bounce@gmail.com";
$to = 'siji_eli@yahoo.com';
$subject = 'Test email'; 
$message = "Hello World!\n\nThis is my first mail.";
$headers = "From: beths86@gmail.com\r\nReply-To: beths86@gmail.com";
$mail_sent = mail( $to, $subject, $message, $headers,"-f".$return_path);
echo $mail_sent ? "Mail sent" : "Mail failed";
I am not getting how this code will notify whether the mail that had been sent got bounced.
Apart from this, is there any other method for the PHP Script to know when the email gets bounced. pls help
Thanks in advance.
Last edited by Benjamin on Fri Mar 26, 2010 7:16 am, edited 1 time in total.
Reason: Added [code=php] tags.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: How to check if a mail has bounced in PHP

Post by requinix »

PHP does not receive emails. You'd have to find a way to configure your mail server to run a script when it receives some type of email.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: How to check if a mail has bounced in PHP

Post by s.dot »

Yup, set the return-path in the header. Then write a php script that periodically checks the mailbox of return-path. Your php script should parse each email, determine if it is a bounce, and handle it accordingly (usually by marking flags in a database).
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
siji86
Forum Commoner
Posts: 30
Joined: Fri Mar 26, 2010 6:15 am

Re: How to check if a mail has bounced in PHP

Post by siji86 »

Hi,

I tried to set up a return path, but the mail is not getting delivered. Please can somebody help.
Here is the code:
$message->setReturnPath('bounces-wez=omniti.com@example.com');
This does not work


Thanks in advance,
Elizabeth.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: How to check if a mail has bounced in PHP

Post by s.dot »

that is not a valid email address you are setting
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
siji86
Forum Commoner
Posts: 30
Joined: Fri Mar 26, 2010 6:15 am

Re: How to check if a mail has bounced in PHP

Post by siji86 »

Hi,

actually what i want to do is append some variables to the return path. Is that possible in php?

Thanks in advance
:)
Post Reply