How to fix PHP mail function not completing sending of e-mail?

Spread the love

Sometimes, we want to fix PHP mail function not completing sending of e-mail.

In this article, we’ll look at how to fix PHP mail function not completing sending of e-mail.

How to fix PHP mail function not completing sending of e-mail?

To fix PHP mail function not completing sending of e-mail, we call mail with the header values.

For instance, we write

$header = "From: noreply@example.com\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header.= "X-Priority: 1\r\n";

$status = mail($to, $subject, $message, $header);

if($status)
{
    echo '<p>Your mail has been sent!</p>';
} else {
    echo '<p>Something went wrong.</p>';
}

to call mail with the $to, $subject $message and the $header string with the metadata for the email message.

Then we can get the result of sending the email from the $status variable.

If $status is set then the email is sent.

Conclusion

To fix PHP mail function not completing sending of e-mail, we call mail with the header values.

Leave a Reply

Your email address will not be published. Required fields are marked *