Jump to content

check email was not sent successfully


peterjc

Recommended Posts

I need to built a system that allow user to send email using the php mail() function.  I would like to know that are there any way to detect the email was not sent successfully to the recipient using php? 

 

For example if the email was not sent successfully, the system could know it and then send an email to notify the user(sender) about sending fail.

 

Thank in advance.

Link to comment
Share on other sites

Unfortunately you are somewhat limited with the mail() function. It will return true/false but if it returns true it doesn't necessarily mean the mail was delivered to the destination, it only means the mail was accepted for delivery. For accurate results in terms of mail delivery information you'll need to use something more advanced like PEAR:Mail.

Link to comment
Share on other sites

Thank for your, the182guy.

 

Never use PEAR's Mail package before.  Will look on it.  Anyway do you know any web site that show how to use pear mail package to check the email was not delivered to the destination?

 

Thank.

 

 

Link to comment
Share on other sites

PEAR::Mail is no different then mail() it only allows you to use something different then the native PHP mailer. It will not tell you if your recipient actually received the e-mail. There are a few other ways though you can use:

 

1. Use a 1x1 pixel image <img src="http://www.yourserver.com/mail-received.php?email=.." width="1" height="1> Ofcourse if their e-mail client blocks images you'll never know who read it.

 

2. Use the Return-Path header. This will send an e-mail back to you in the event a mail could not be received. You can use PHP to read incoming mail (http://www.evolt.org/article/Incoming_Mail_and_PHP/18/27914/index.html)

 

Your best option is to use http://www.campaignmonitor.com/ this is a tool that provides you with all the needed statistics

Link to comment
Share on other sites

PEAR::Mail is no different then mail() it only allows you to use something different then the native PHP mailer. It will not tell you if your recipient actually received the e-mail.

 

PEAR::Mail gives better error messages as opposed to mail() which will just return false. Due to the nature of SMTP it is not possible for any piece of code to send an email and instantly determine whether the mail arrived at it's destination with 100% accuracy. You can only add checks like you said which again can't be 100% accurate.

 

The 1x1 pixel method will only work for a minority of recipients because most email clients disable images in the email content by default for security and privacy reasons. Having said that it is very popular with email marketing software which means it could be counterproductive to use due to this being a hallmark of a 'marketing' email or aka spam and thus the email being treated as such by some spam filters.

 

If this is for some sort of registration script then using an activation link in the email is one way of verification.

Link to comment
Share on other sites

For accurate results in terms of mail delivery information you'll need to use something more advanced like PEAR:Mail

 

IMO this suggested to the OP that PEAR::Mail notifies him whenever a mail is not opened/received while PEAR::Mail merely allows you to send your mail through something different then the built-in mailer like SMTP.

Link to comment
Share on other sites

For accurate results in terms of mail delivery information you'll need to use something more advanced like PEAR:Mail

 

IMO this suggested to the OP that PEAR::Mail notifies him whenever a mail is not opened/received while PEAR::Mail merely allows you to send your mail through something different then the built-in mailer like SMTP.

 

This was meant in relation to the mail() function and with the limitations of SMTP in mind, perhaps I should have said more accurate.

 

In any case I was hoping that it would prompt OP to take a look at PEAR::Mail to see if it can meet his requirements which are up to now quite vague. If OP can be more specific about what he is doing then it will help, e.g. are you developing email marketing software, a registration form, contact us form? mail() is particularly inefficient if you are looping it to send to many recipients because it creates and destorys a new connection to the SMTP server with each call.

Link to comment
Share on other sites

OK. Here are explanation about the web site.

 

After user login to the web site, user need to fill in some detail via a HTML form and save the detail to the database. The detail is actually the email content. 

 

Meanwhile, user can see many advertisers (the advertisers email are stored at database).  At the advertiser listing, user can choose which advertisers the user want to send the detail. 

 

Example,  if the user want to send the detail to the advertiser, user can click a link "send detail", and the detail will be send to the advertiser via email.

 

The problem is, some of the advertisers email is not working.  So, user detail was not send to the advertiser.  So, the web site need to notify the user that the detail failed send to the advertiser.

 

So, i need to know how could the system know the email failed send to the advertiser, so that the system could notify the user.

 

Hope you guy could understand it.

 

Thank.

Link to comment
Share on other sites

There is no 100% guarantee method, known methods are:

 

1. Use a 1x1 pixel image <img src="http://www.yourserver.com/mail-received.php?email=.." width="1" height="1> Ofcourse if their e-mail client blocks images you'll never know who read it.

 

2. Use the Return-Path header. This will send an e-mail back to you in the event a mail could not be received. You can use PHP to read incoming mail (http://www.evolt.org/article/Incoming_Mail_and_PHP/18/27914/index.html)

 

But this does not guarantee that your user will be notified if the mail was not received.

Link to comment
Share on other sites

i try using the Return-Path but without success.  The return-path is set back to the web host email.  I am using shared host.

 

I did google the web and found some article said put the return path at the additional parameter, but it still does not work.

 

mail($to,$subject,$message,$headers,"-f someone@domain.com");

 

Anyone know what is the problem? 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.