How do i make sure that my mail($to,$subject,$msg); delivers the mail
My computer has got apache installed(localhost), so i made a signup option, and there is an email option to which i send a mail for activation of account. I have an internet connection, now if in the PHP script, i write mail($to,$subject,$msg); will this code deliver the mail to the desired recepient because开发者_开发知识库 it is not sending it.
There is no way to be 100% sure an email was received by a recipient.
The mail()
function returns a value depending on whether there was a problem sending the email or not. You would do that like this:
$successful = mail($to,$subject,$msg);
if (!$successful)
{
// The email was not sent
}
If the value of $successful
is false
then the server had an issue sending the email. So add that to your code and see what happens. If $successful
is true
then the server is sending the email ok and your problem may lie with spam filters that are receiving the email and deleting it. You can learn more about how to prevent that in this question.
You also need to include headers:
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to,$subject,$msg,$headers);
Without headers you'll probably get marked as SPAM by the recipient mail server.
精彩评论