I have database of approximately 10k users who have subscribed for newsletters. I am changing my site from asp to php. I am sending newsletters by cron job. I want to track the record of unsuccessful delivery report. How is it possible? Please Guide me, Thanks.
2 Answers
In php when you sending mail with mail function you should check with condition
if(mail($to, $subject, $message, $headers)){ // Successfull mail delivery } else { // Code for un-successfull mailing }

- 990
- 7
- 18
-
Not really a good solution to what hes trying to do (as i understand it)... see my answer. – prodigitalson May 02 '11 at 06:02
In php when you sending mail with mail function you should check with condition
if(mail($to, $subject, $message, $headers)){ // Successfull mail delivery } else { // Code for un-successfull mailing }
This is highly inaccruate for what the OP is actually trying to do... From the manual:
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.
Depending on server type and configuration you will get varying results. Its better to use SMTP to ensure a proper and consistent interface. Generally i would use a library to do this... you could do it yourself manually using sockets, but why reinvent the wheel? There are 3 libraries i use depending on the project...
For this level of interaction i would use SwiftMailer or Zend_Mail. Both of these support getting information from SMTP as well as sending the message, so for example you can get info about failed recipients (SwitftMailer example). Both Zend and Swift also support custom spools queues so you can more deeply integrate queuing and sending messages in an application aware way. SwiftMailer also has batchSend functionality... i assume this is available in Zend_Mail as well but ive never dug in to deep.
This is only half the battle though... In order to actually read the NDR's you need to script logging in to the mail store, looping through the messages, and then parsing the headers and/or the message body of the NDR (make sure you refer to the RFC docs listed on the wikipage), then take action based on that. Recently i used Zend_Mail_Storage to handle this. If you need to do this then you probably also want to just go ahead and use Zend_Mail for sending as well since Storage is included in the component. Youll need to take a look at the RFC for NDR's and status codes in order to parse properly.
Overall, if at all possible, i recommend just integrating a 3rd party service like MailChimp or Constant Contact. Its a a lot less work, and unless you have a team of devs working on this over time a service is probably going to yield better results across the board.

- 60,050
- 10
- 100
- 114
-
Seconding a third party service to handle all of this for you - generally less of a headache and less pain on your end (unless you are spamming.) Here is a list you should check out: MailChimp, Constant Contact, and AWeber. – JonLim May 04 '11 at 19:03
-
Yesterday i sent a test newsletter to a database of 54000 users by using phpmailer. After aprox 10 minutes script stopped and error shown on page like 'INTERNAL SERVER ERROR OCCURED'. I am confused. What type of problem is there? Please help. – SohailRajput May 05 '11 at 07:21
-
Thats jsut a gneric code for a server side error so I have no idea. You should look at your error logs and get the actual PHP and/or http errors. Post the real error messages to a new question along with your process for sending the mails. My guess would be you exhausted the time limit for the script or ran out of memory or something. Hint: dont just add all the recipients to the BCC or TO fields, you need to queue sending. – prodigitalson May 05 '11 at 17:26