您好我想用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);
希望有人能解决这个问题
答案 0 :(得分:2)
在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更改为this版本会更好。
答案 1 :(得分:0)
我有完全相同的问题。我用肮脏的黑客修复它。
用以下代码替换函数(以public static function ValidateAddress($address) {
开头):
public static function ValidateAddress($address) {
return true;
}
这将验证您提供的任何地址,任何!
在使用PHPMailer之前,您应该自己检查地址。我不知道如果你不知道会发生什么,只要检查一下地址。