Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Success verification of mail() function PHP

Tags:

php

Is it possible to check if the php can get some kind of a ping/flag back from exchange mail server to say "yes, email has been sent off to the intended recipient"?

According to the PHP manual, the return of mail() boolean could mean; "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."

Does this mean, PHP can return success but actually there could be a problem on the mail server that php wouldn't know about it? and in this case no email has been sent and the user is none the wiser?

TIA Jared

like image 981
Jared Avatar asked Oct 15 '22 06:10

Jared


1 Answers

The mail() function will just connect via SMTP to the server and send the message. Then if the server says the server has received the message, mail will return successfully.

In the meantime, things can go wrong. The user's account could be deleted, the harddisk on the mailserver could crash, the SMTP server could fail to find the user's mail server. The user's mail server could reject the message because the user's mailbox is full. Many, many things could go wrong.

This isn't PHP's fault. And no reasonable improvement could be made to any programming language API to make sure someone got the message. But some companies like CampaignMonitor offer a paid service that will check for bounces and if people open the message to update mailing your mailing lists. Using APIs from services like these, you could check in a few days if the message was successfully received.

So the PHP docs are just saying, 'We can only tell you if the first SMTP server said they got it. Any number of issues could happen between the computers from there to the person with the email account.'

like image 144
Robert Avatar answered Nov 04 '22 02:11

Robert