PHP:查看不成功的电子邮件

I'm trying to figure out how to display a list of unsuccessful emails sent and a way to test it out. I can display a list of the emails that were sent, but I'm unsure on how to retrieve the list of emails that were unsuccessfully sent out.

Here is what I'm using to retrieve it from the mysqldb:

            //get the email address list
            $query = "SELECT email FROM users 
                    WHERE id IN (SELECT participant_id FROM roster AS ur WHERE ur.roster_id=".$roster['roster_id'].")";
            $result = mysql_query($query);
            $emailstring2 = "";
            $email2 = $result;
            while ($row = mysql_fetch_object($email2)){
            $emailstring2 .= $row->email. "
 ";
}

In the message section, I retrieve it via:

   $message .="Successful emails: 
".$emailstring2." 
";

How would I achieve this?

One keyword will get you the ones not sent: NOT

WHERE id NOT IN 

You can't do this from PHP in a simple manner like this.

Think of it as a letter going through the postal service. All you can do is give the letter to the postman and hope that it reaches its destination. The postman will not come back and tell you if delivery was successful, or if the letter was actually read by the recipient. PHP's mail() function (and its derivatives) return TRUE to indicate that the message was accepted for delivery attempts, not that it was successfully delivered. (Delivery may not happen for hours or days.)

As a result, the best you can do is approximate delivery notification. There are a few ways you can do this:

  • Use a tracking pixel in the email that gets pinged when the user opens the message. However, given that most email clients nowadays default to "do not show images," I think this technique is rather unreliable.
  • Send each message with a bounce address unique to the recipient. If the message can't be delivered, it will return to the custom address -- and that return message can be used to indicate that the original recipient's email address is no good. This is probably the most accurate method but is not simple to configure.
  • Use return receipts. Like tracking pixels, I think most email clients default to never send these, so this is likely unreliable as well.
  • Use delivery status notification. This will require using a server that supports it and sending to a server that supports it.
  • Send your mails through a service that will do this sort of tracking for you. (E.g. MailChimp or Constant Contact)