I’m using PHPMailer and $mail->Send() is returning an error, my problem is when I use this email-string “noreply@pleasenoreply.com” within $mail->SetFrom(), but in the other hand it works fine with almost any other email i.e “hello@hello.com”.
After debugging the code I found out that the problem is in the file class.phpmailer.php over the function ValidateAddress(). It seems that the email “noreply@pleasenoreply.com” is not valid by FILTER_VALIDATE_EMAIL nor the preg_match
PHPMailer – class.phpmailer.php – line 550:
public static function ValidateAddress($address) {
if (function_exists('filter_var')) { //Introduced in PHP 5.2
if(filter_var($address, FILTER_VALIDATE_EMAIL) === FALSE) {
return false;
} else {
return true;
}
} else {
return preg_match('/^(?:[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+\.)*[\w\!\#\$\%\&\'\*\+\-\/\=\?\^\`\{\|\}\~]+@(?:(?:(?:[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!\.)){0,61}[a-zA-Z0-9_-]?\.)+[a-zA-Z0-9_](?:[a-zA-Z0-9_\-](?!$)){0,61}[a-zA-Z0-9_]?)|(?:\[(?:(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\.){3}(?:[01]?\d{1,2}|2[0-4]\d|25[0-5])\]))$/', $address);
}
}
Why is that possible?? does anyone have any idea what is going on??? why this email “noreply@pleasenoreply.com” is not allow?
I don’t know why that specific address is being rejected and others aren’t, but generally, you need to specify not only a valid E-Mail address as the from address, but one that is handled on the mail server you’re sending the message from.
Otherwise, either the sending server is going to deny sending, or the receiving server is very likely to throw away the message as spam.
The usual policy is to specify
noreply@yourdomain.com(yourdomain.com being your website domain). On some servers, you need to actually set up that address to be allowed to send mail from it.