$subjt = $subject;
$message = $message;
$toinfo .= $snteadd[$i];
$headers = "MIME-Version: 1.0
";
$headers .= "Content-type: text/html; charset=iso-8859-1
";
$headers .= "From: <$fromemailid>
";
$headers .= "Cc: <$sendCC>
";
$headers .= "Bcc: <$sendBCC>
";
$headers .= "Return-Path: <$fromemailid>
";
$headers .= "Errors-To: <$fromemailid>
";
$headers .= "X-Mailer: PHP 4.x". phpversion()
@mail($snteadd[$i], $subjt, $message, $headers);
Return Values
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.
Then you can do:
if (@mail($snteadd[$i], $subjt, $message, $headers))
{
echo 'delivered to smtp';
}
else
{
echo 'not delivered to smtp';
}
If you want check mail reach the your sender, then probably better solution will be get link to your script with unique arguments to determinate mail id, and get information in mail text to click link.
The mail
function returns true
on success or false
on failure.
if (!@mail($snteadd[$i], $subjt, $message, $headers))
{
// It failed...
Check the return value of mail
function which returns false
when there it fails.
if(@mail($snteadd[$i], $subjt, $message, $headers) === false) {
// mail failed.
}
Just to expand on previous answers, the @
is used to explicitly suppress error messages from the following function being displayed - so what your code does is send an email and DON'T TELL ME if it it fails... This is usually only good if you either a) don't care or b) are checking that it worked yourself - eg with an if block as shown elsewhere
While the mail()
function returns true on success and false on failure, the status it reports only means "accepted for delivery by the local server", absolutely not "delivered".
The SMTP protocol used for most email guarantees nothing. It should try to deliver the e-mail, sometime; again, there's no guarantee that it will be in ten minutes, tomorrow, or this month (it happens). Even worse, there is no reliable way to tell whether a mail you've sent has actually been delivered to the intended recipient.
Even if the e-mail is delivered to the recipient, it may get shuffled to the spam bin, and the user won't see it.
In other words, the only thing that you can be sure of with e-mail is whether or not you've sent it; anything beyond that is uncertain. (see also this for other possible pitfalls)
In case someone else is wondering why the "Return-Path" header they are setting is not being honored, many php settings replace that header with something else, usually a default email address for the server (eg., something@webserver.domain.com). Use the (often overlooked) 5th parameter, $additional_parameters in this way:
mail($toMail, $subject, $message, $other_headers, "-fyour_return_path_email_address@whatever.com")
The your_return_path_email_address@whatever.com is the email you want the return path to be. The -f
part that precedes this makes the "envelope sender" that email address.