Success verification of mail() function PHP - 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

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.'

Related

PHP - In which cases can an email not be accepted for delivery?

With the following statement we will get a boolean whether the mail we try to send gets accepted for delivery or not:
if(mail($to $subject $message $headers))
Since I always get true even if I am not connected to the internet, I assume that this response has nothing to do with the fact if it gets sent for real or not. So in which cases can I get false? And where does this 'getting accepted for delivery' happens (on my computer, on the server, in the aether...)?
The mail() function uses the system mailer - which can be sendmail, or a mail transfer agent directly. The return value only indicates that the message was delivered successfully to whatever intermediary your system is configured with (usually sendmail on linux systems).
If you need actual data on deliverability, you could use a third party mail service such as SendGrid or MailGun, etc, which use APIs to send and also can report back delivery status, and other data.
As explained in the php.net documentation,
mail() Returns TRUE if the mail was successfully accepted for
delivery, FALSE otherwise. 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.
In other words, the mail() function returns true if he gets all the values he needs to send the mail. But cannot know if the mail was received or not because PHP is not the one sending the mail. The mail server (most likely exim) is.
There's a nice PHP library that can help you validate if an email is valid/exists and belongs to a user. It's called kickbox
So before using the mail() function, you could run the email in kickbox and in combination with the returned true of mail() you can assume the mail was sent out as long as exim does his job.
You can also use an API like MailJet to send out your email in your name instead of using the servers mail server and receive a status report directly from the API to know if the mail server was successful or not in sending the mail.
As most of the replies here already answered your question, may I suggest an alternative which is PHPMailer (https://github.com/PHPMailer/PHPMailer)?
It's a library for sending emails in PHP and you can define the SMTP, account info and even attach files when sending out emails. It even allows for SMTP debugging of sorts as well using "$mail->SMTPDebug = SMTP::DEBUG_SERVER;" for example.
Quite easy to use too. You can refer to the official tutorial here: https://github.com/PHPMailer/PHPMailer/wiki/Tutorial

Record/copies of PHP mail() previously sent from our website?

Should there be a record of all php sent mail (via our hosts mail() function) anywhere?
Our web developer made an oversight and all enquiries sent via the our host's (godaddy.com) mailer relay for the last 2 months were rejected by our local mail server. Naturally, our server doesn't keep any rejected emails.
I have spoken to godaddy.com and they claim there is no record, however I'm not particularly confident with the answer.
Is there anything I can do? The enquiry form is now fixed (used Mandrill), so that's not an issue.
No, the mails are gone now.
Rejected mails that a mail server tried to send usually go to the mail admin account of the sending server as a bounce - however, even that account might not be set up or failing or rejecting mail, so the mail server will get rid of these undeliverable mails that double-bounced by deleting them from the queue.
You might get an idea of what was tried to mail if you are able to get your hand onto a mail server logfile, but assuming this is in the hands of your hosting provider, your chances are low: 1. these logs would only give you an idea of which mail addresses were involved, but no content. 2. the log files usually get deleted quickly because they'd serve no regular purpose.

How to track when mail comes out of my server and if he succed?

I need to track when the mail leave out my server to know possible issues:
Recipient inbox is full;
Recipient's server rejected
whatever..
The main problem is: how?
Currently I use a CentOS server. I can track only if my server receive and queue the mail to sent, but not the process of sending it self.
Is it a issue which could not be solved with PHP? Where should I start follow?
As mentioned in the comments above, one way is to check your mail server's logs. These will show whether or not the receiving MTA accepted delivery, or if delivery failed for some reason.
Another way is to send the message from your PHP script using phpmailer, through a hosted SMTP server which provides you with delivery information, such as http://www.sendgrid.com or http://www.ultrasmtp.com.

How to get information of mail delivery in PHP

I want to send mail by PHP mail() function.
Does PHP mail() function return delivery status? If not then what is the way to find whether my mail is delivered or not in PHP?
Is php mail() function returns delivery status
No. There is no common way to tell an E-Mail's actual delivery status. mail() will tell you only whether the E-Mail has been accepted by the outgoing server.
Here is a list of approaches to request a delivery notice, but none of them is waterproof.
If you have trouble with E-Mail arriving, there are several related SO questions, among them this one.
It returns a status telling you if it has been successfully delivered to the MTA responsible for actually sending the mail.
You cannot find out if the mail has been actually delivered to its recipient or not without setting up a special mailbox which receives bounces for your emails. If you decide to create one and set the headers to ensure bounces go there remember that it might take some time before a bounce arrives so right after calling mail() and getting a TRUE return value, you simply have to assume the mail has been sent successfully.
You can check /var/log/mail.log, which is the usual location of the sendmail log and only if sendmail has been configured properly in syslog.conf.
# Log anything of level info or higher.
* .info;authpriv.none;cron.none
# Log all the mail messages in one place.
mail.* /var/log/maillog

Php mail(), how to get undelivered address list?

I'm getting single emails, for each undelivered address that mail() send couldn't reach.
Since this can be a painfull process, to keep copy pasting every single address, I'm wondering if it's possible to access a LOG or something ?
Some notes:
- I've got this app running on a GoDaddy server (I know it sucks);
Thanks for your atention ;D
There is no log as such, because feedback from the receiving mail server is not immediate. There's only the "undeliverable" messages that get returned to you.
However, it should be possible to specify a reply-to or errors-to address pointing to a separate mailbox. That would make it easier to find out which recipient addresses failed.
That is the best way I can think of to group failed messages.
I'm wondering if it's possible to access a LOG or something ?
Maybe - it depends on what the MTA (mail transport agent) is, how it's configured and whether you have the permissions to access the file.
I've got this app running on a GoDaddy server
Then the above are all questions for your GoDaddy provider.
The MTA log should record details of messages which the MTA failed to offload elsewhere but the elsewhere may be a smart relay (i.e. still on the sending side) - in which case you'd need to look at the relay MTA's logs to see if it managed to pass the message on to one of the recipient MXs. Even if the message got as far as a recipient MX, you don't know that it was successfully delivered. By convention, the receiving system should send back a DSN if it fails (and you can specifically ask for a DSN regardless of outcome) but a lot of systems don't implement this properly.
Regardless it may provide information about some messages which fail - you'd need to poll the return mailbox to identify failures.
C.
If mail() fails immediately, it returns false and you went get any e-mail. However, if a problem arises after the mail has been sent but before it has been received, you get an e-mail.
The mail() function will send the e-mail to some mailserver, which will send it to another, until it reaches its destination. When the user does not exist, this is only discovered at the destination mail server and it responds with an e-mail, called a bounce.
There is no way to group these bounce e-mails, as the destination mail servers do not know that they came from the same script.
Another option you have is to pipe the incoming emails to a PHP script and process it that way. How this is accomplished depends on the server setup you have and whether your server is set up to use sendmail or exim.
A good tutorial on this is located here.

Categories