2

We send a lot of emails to a lot of our users (ranges in 20k+ per day). One of the major problems we face are invalid or dead emails - sometimes our users delete their accounts, change their email address without updating their profile, or our email database builders simply caught emails that are invalid or no longer active. These unresolved returned status messages keep not only piling up on our webmaster account, but also waste precious server resources and flag us as spam more often because of the repeated attempts.

Now, while our mail server is set up to keep trying to send an email to an address that returns "temporarily unavailable", I would like to be able to receive status messages into PHP immediately after sending. For example, when my Sender class sends an email, I would like to know the status message that was returned - whether the email is no longer active, or the server does not exist, or the email was simply moved to another address.

Naturally, I want to be able to receive a status message of a delayed email as well. So if an email does not get sent because the recipient email address is temporarily unavailable, I would like to get the "temporarily unavailable" message back into Php, but I would also like the real one to get passed back once the sending succeeds (for example, if the email does go through 2 days later).

Is there a library that would help me achieve this? What are the most common approaches to this problem, if any?

Swader
  • 11,387
  • 14
  • 50
  • 84

2 Answers2

2

Like most questions about PHP and mail this is mainly about the MTA.

Bulk emailing is a science in its own right (OK, so more like a black art) and at these kinds of volumes you need to up your game a lot if you want reasonable rates of deliverability.

But back to the question.

An awful lot of this is about how you configure your mail server. AFAIK, most MTAs will only send back a failure message when the message is removed from the queue (e.g. after the last attempt at delivery). Which gives 2 options for tracking each attempt:

1) parse the log files

2) set the number of attempts to 1 (and optionally handle re-queueing yourself).

Given that a message can fail to be delivered after it has successfully departed from your server, it makes a lot of sense to use delivery status notifications (i.e. bounce emails) to track the progress of messages - so using option 2 avoids having to build different code for handling different scenarios.

Without knowing what OS this is running on, nor which MTA, it's impossible to give more specific recommendations.

symcbean
  • 47,736
  • 6
  • 59
  • 94
  • We are flexible on the MTAs and would not mind replacing it if one would perform better for our needs. The OS is Linux. Right now, we use sendmail in some cases, and Zend_Mail_Transport_Smtp in others. – Swader Jul 05 '11 at 11:51
  • I have created a library for sending for my company. We can process (parse and create) 1000 different emails to 1000 different recipients from 1000 different senders in under 2 seconds, while the actual sending (the ->send() command) takes 30 seconds for the whole 1000. This is acceptable for us. Now, we use a direct Zend transport for latching onto the server and sending that way. In a way, we don't use a real MTA. As previously mentioned, the server is Linux based. As for your suggestions - do you perhaps have an example of solution 2? – Swader Jul 17 '11 at 14:46
1

symcbean's answer gives many theorical inputs and several means to handle your case.

Besides, maybe you could have a look on how other libs or builtin functions work. For instance, you can have a look at :

i used PHPList some times ago but it was already a reliable solution. I don't know the PHP Mailer class but i may be worth a try (or a least a look on how they deal with similar issues).

Regards,

Max

JMax
  • 26,109
  • 12
  • 69
  • 88
  • I don't think either of those has the functionality I am after, these are "sender" libraries, but they don't seem to be able to parse the return messages/statuses. That part I still must do manually, and since I have built a fairly decent sender library for my company (hence only needing the "handler" part), I won't be needing those two. Thanks though! – Swader Jul 17 '11 at 14:42