1
votes

I'm using PHPMailer and $mail->Send() is returning an error, my problem is when I use this email-string "[email protected]" within $mail->SetFrom(), but in the other hand it works fine with almost any other email i.e "[email protected]".

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 "[email protected]" 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 "[email protected]" is not allow?

1
Please always quote the exact error message. - Pekka
Have you checked exactly which branch of that code is failing? I can't see the filter_var one bombing on such a simple email, so possibly the regex is buggy. ... unless filter_var is actually doing a DNS lookup on pleasenoreply.com, which doesn't resolve. - Marc B

1 Answers

1
votes

my problem is when I use this email-string "[email protected]" within $mail->SetFrom()

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 [email protected] (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.