简体   繁体   中英

determine true mail sent status (PHP mail())

I am using inbuilt support of sending mails in php.

$status=mail($to,$subject,$message,$headers,"-f $from");

I am on LAMP server and we use sendmail Unix utility. php mail() returns true status if it has handed over the mail to sendmail so we can not be sure that whether a mail has been sent successfully of not. Now what I want is to make some socket connection between php and sendmail so that I can get the "True status" whether mail has been sent or not.

I am very new for PHP. This is the part of the first problem which I am solving in PHP. I Goggled but I am not getting exactly how to proceed further. Guide me how can I get true status whether a mail has been sent or not at PHP end?

It won't get you anywhere if you check that your local sendmail demon has received the mail. The important part would be that sendmail was able to forward the mail to another mail server.

But this really is also only half of the truth, because that server need not be the final destination of the mail. So after the mail left your sendmail demon, you cannot say anything about whether or not the mail reached it's destination or not.

If you need to be sure, do the obvious thing: Include a link in the mail that needs to be clicked.

Otherwise, assume your local sendmail is working (probably monitor if it really is), and simply send the mail.

Option 1: Socket connection: read the RFC , then write a standards-compliant SMTP client program. [don't even bother unless you want to throw a few weeks of your life away]

Option 2: Use PHPmailer or SwiftMailer or one of the other bazillion mailing libraries that have already written a standards-compliant SMTP client that will actually tell you if the mail was successfully sent or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM