php - detect if email is sent

if(@mail($emailRecipient, $subject, $message, $headers))
{
  echo "Mail Sent Successfully";
}else{
  echo "Mail Not Sent";
}

Firstly, I'd suggest using a third party mail library (SwiftMailer, PHPMailer, Zend_Mail...) for sending email instead of the built in mail function. Composing mail is more complicated than most people realize, especially if you want to do multipart and/or HTML formatted email.

Secondly, beyond checking if the message was successfully delivered to the first (usually local) email service, it is pretty much impossible to determine if an email was sent. This is due to the way email inherently works and there is little than can be done about it.

The only thing you can (and really should) do, is make sure your system handles bounced emails in a sane way. eg. If an email address continuously bounces, consider unsubscribing the address.

Tags:

Php

Email