Page 1 of 1

How to check if a mail has bounced in PHP

Posted: Fri Mar 26, 2010 6:35 am
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.

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

Posted: Fri Mar 26, 2010 7:30 am
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.

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

Posted: Fri Mar 26, 2010 9:34 am
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).

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

Posted: Sat Apr 03, 2010 12:51 am
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.

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

Posted: Sat Apr 03, 2010 1:11 am
by s.dot
that is not a valid email address you are setting

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

Posted: Sat Apr 03, 2010 2:04 am
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
:)