I am told that it is possible for sendmail to give the transaction log (or possibly last status) back to php mail so you can verify if the mail server was actually able to send the message. How does one actually go about doing this? I can't find any reference to it. In short I want to know if sendmail was actually able to communicate to the recipient and have php mail() or any method know.
3 Answers
just place it within if
condition
if(mail($param)){
echo "email sent";
}else{
echo "there is some error";
}
550 for spam or a different one for user doesn't exist
it is not possible to detect.

- 5,528
- 5
- 50
- 87
-
Sure but what if the email bounced and got 550 for spam or a different one for user doesn't exist? I won't know. – UKUser35 Sep 14 '16 at 06:26
-
Please note that the `mail()`-command returns a boolean if the system's mailclient received the message from PHP. In other words: if sendmail fails to send the message (for any given reason), the `mail()`-command would still return true. – Giel Berkers Sep 14 '16 at 06:40
-
A colleague told me that Rackspace were somehow able to make it work (I don't host with them now) and there was some way of getting sendmail to talk with php mail (or maybe it was a different way) and I just wondered if php mail could be therefore made any better and more detailed. – UKUser35 Sep 14 '16 at 07:12
-
you might be talking about something like http://stackoverflow.com/questions/4603850/php-check-who-had-read-sent-email – urfusion Sep 14 '16 at 07:39
I don't believe this is possible without keeping track of the logs of sendmail itself. So you:
- Have to have access to the mail logs on the server (or at least of the e-mail from which you are sending your mail)
- Poll these logs for success / or failure messages
- Trigger a method according to these logs.
Note that these mail logs are asynchronous with your PHP code. A bounced mail can come a couple of seconds after your script is already finished executing. Therefore it is impossible (or at least, very inefficient) to have PHP know if the message sent by mail()
was successfully delivered or if it bounced.
It could also be that sendmail has it's own interface to poll these kind of things using the command line, but I would not know about that.
Anyway, it's a tricky thing to set up. But as with most tricky things, there's probably somebody who already wrote something like this ;-)

- 2,852
- 3
- 39
- 58
As I understand you mean "handed over to ANOTHER/EXTERNAL smtp server".
AFAIK It is not possible with sendmail by sendmail.org (especially sendmail-8.12.0+).
It may be possible with another MTA/SMTP servers but the transaction may take long time (minutes).
You will get only result of initial/first delivery attempt.
Something like "report successful transfer to another server taking less than 3 seconds" could be implemented in MTA/SMTP server
but AFAIK it would require significant modifications of most MTA/SMTP servers.

- 10,493
- 3
- 23
- 47