0

您好,我想用 hotmail 帐户发送邮件,我得到:

SMTP -> FROM SERVER:220 mx.google.com ESMTP q44sm31046347eep.5
SMTP -> FROM SERVER: 250-mx.google.com at your service, [91.203.134.106] 250-SIZE     35882577 250-8BITMIME 250-AUTH LOGIN PLAIN XOAUTH XOAUTH2 250-ENHANCEDSTATUSCODES 250     PIPELINING
SMTP -> FROM SERVER:502 5.5.1 Unrecognized command. q44sm31046347eep.5
SMTP -> ERROR: STARTTLS not accepted from server: 502 5.5.1 Unrecognized command.    q44sm31046347eep.5
SMTP -> FROM SERVER:250 2.1.5 Flushed q44sm31046347eep.5
Language string failed to load: tls 

我根本不知道为什么会有 mx.google.com !!!这是我的代码

require_once('phpmailer/class.phpmailer.php');
    $defport=25;
    $sendmail='MAIL@hotmail.com';
    $mailpass='PASS';


    $mail = new PHPMailer(true);
    try {
    $mail->IsSMTP(); // send via SMTP
$mail->Mailer = "smtp";
if($defport==25) $mail->SMTPSecure   = "tls";
    $mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPDebug = 2;
$mail->Host = 'smtp.live.com';
    $mail->Port  = 25;
    $mail->Username = $sendmail; // SMTP username
    $mail->Password = $mailpass; // SMTP password
    $mail->From = $sendmail;
$mail->FromName = $sendmail;
    $mail->Subject = 'test';
    $mail->Body = 'test';
$mail->WordWrap = 50;
    $mail->AddAddress ('foo@foo.bar.com');
$mail->IsHTML (true);
    $mail->SetLanguage("en", "phpmailer/language/");

    $mail->CharSet = 'utf-8';

   $mail->Send();
 echo "Message Sent OK\n";
} catch (phpmailerException $e) {
  echo $e->errorMessage(); //Pretty error messages from PHPMailer
} catch (Exception $e) {
  echo $e->getMessage(); //Boring error messages from anything else!
}
?>

你知道这可能是错的吗?

我尝试了另一个版本的 phpmailer (5.2.2) 并收到以下错误:

Warning: preg_match() [function.preg-match]: Compilation failed: reference to non-existent subpattern at offset 626 in ***/phpmailer/class.phpmailer.php on line 738
Invalid address: foo@foobar.bar.com

第 738 行是:

    return preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[   ])+|(?>[    ]*\x0D\x0A)?[   ]+)?)(\((?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\]]){7,})((?6)(?>:(?6)){0,5})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?>((?6)(?>:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address);

希望有人能弄清楚

4

2 回答 2

1

在您的 class.phpmailer.php 中使用它。phpmailer与你的php版本一定存在兼容性问题。

public static function ValidateAddress($address) {
    if ((defined('PCRE_VERSION')) && (version_compare(PCRE_VERSION, '8.0') >= 0)) {
      return preg_match('/^(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){255,})(?!(?>(?1)"?(?>\\\[ -~]|[^"])"?(?1)){65,}@)((?>(?>(?>((?>(?>(?>\x0D\x0A)?[     ])+|(?>[    ]*\x0D\x0A)?[   ]+)?)(\((?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-\'*-\[\]-\x7F]|\\\[\x00-\x7F]|(?3)))*(?2)\)))+(?2))|(?2))?)([!#-\'*+\/-9=?^-~-]+|"(?>(?2)(?>[\x01-\x08\x0B\x0C\x0E-!#-\[\]-\x7F]|\\\[\x00-\x7F]))*(?2)")(?>(?1)\.(?1)(?4))*(?1)@(?!(?1)[a-z0-9-]{64,})(?1)(?>([a-z0-9](?>[a-z0-9-]*[a-z0-9])?)(?>(?1)\.(?!(?1)[a-z0-9-]{64,})(?1)(?5)){0,126}|\[(?:(?>IPv6:(?>([a-f0-9]{1,4})(?>:(?6)){7}|(?!(?:.*[a-f0-9][:\]]){7,})((?6)(?>:(?6)){0,5})?::(?7)?))|(?>(?>IPv6:(?>(?6)(?>:(?6)){5}:|(?!(?:.*[a-f0-9]:){5,})(?8)?::(?>((?6)(?>:(?6)){0,3}):)?))?(25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?>\.(?9)){3}))\])(?1)$/isD', $address);
    } elseif (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);
    }
}

如果你把你的phpMailer改成这个版本会更好。

于 2013-02-21T13:05:47.397 回答
0

我有完全相同的问题。我用一个肮脏的黑客修复了它。将函数(以 开头public static function ValidateAddress($address) {)替换为:

public static function ValidateAddress($address) {
    return true;
}

这将验证您提供的任何地址,任何

在将地址与 PHPMailer 一起使用之前,您应该自己检查地址。我不知道如果你不这样做会发生什么,只是检查地址。

于 2013-06-19T18:10:45.247 回答