Jim999
09-20-2004, 04:13 PM
Hi
ok, here is what I want to do:
I need to send emails to a certain email list, and I want some kind of auto indication of the certain email addresses that bounce back (no matter the reason, mailbox full; not valid address etc.)
if I can make all the bounced emails to come to a certain script of mine - I can (I think I can) then store them in a text file automatically so I resend them.
Anyone knows how to do this? I know PHP - is there a way in PHP?
thanks
stephenM
09-20-2004, 04:22 PM
As long as the recipient's server actually bothers to send back a notice in the event of a failure, then yes it's certainly possible to parse bounced error notices via PHP.
Firstly you'll need to set up an email account in your mail account (probably Exim) to point at your PHP script.
The tricky part comes when you try to detect bounced mail messages, because each e-mail program produces different output in the event of a failure. But hopefully there will be some kind of regular pattern such as *failure notice* or such.
Now you have to build some regular expressions to detect a failure message, probably using ereg() [http://uk2.php.net/ereg].
You say you then want to resend them, but is that a good idea? If it's failed once, it'll most likely fail again and again. Remeber that when you submit a mail message it doesn't just get delivered once, your mail server usually attempts to re-send it at least 3 times. So it's probably best to work out what to do with each mail message depending on what the error actually is, because chances are if the mailbox you're trying to email is just over quota then it'll get fixed soon.
Jim999
09-20-2004, 04:31 PM
Originally posted by stephenM
You say you then want to resend them, but is that a good idea? If it's failed once, it'll most likely fail again and again. Remeber that when you submit a mail message it doesn't just get delivered once, your mail server usually attempts to re-send it at least 3 times. So it's probably best to work out what to do with each mail message depending on what the error actually is, because chances are if the mailbox you're trying to email is just over quota then it'll get fixed soon.
yes, parsing the error message I will get I want to determine just if it's a full mailbox or an invalid address, and if it's just a full mailbox - i want to resend in a week or so. that was the idea.
1) let's say i'm on virtual hosting, how can I set a certain email address to be able to point the bounced emails to my PHP script.
2) what will I get to my PHP page when an email bounced? will it be in the $POST vars or $GET or what?
thanks
stephenM
09-20-2004, 06:04 PM
1) let's say i'm on virtual hosting, how can I set a certain email address to be able to point the bounced emails to my PHP script.
If you're on a CPanel machine using Exim (you probably are because the whole internet seems to be controlled by CPanel :stickout: ) then you need to edit the following file:
/etc/valiases/your_domain.com
And add the following line:
your@domain.com: "|/path/to/your/directory/script.php"
That's the easy part. Now for the email parsing, I've found a really useful article on it:
http://gvtulder.f2o.org/articles/incoming-mail/
I hope that helps :)