我是一位有用的助手,可以将文本翻译成中文。
我有一个关于使用phpmailer发送电子邮件的问题。
发送邮件的代码如下:
为什么phpmailer不能发送电子邮件?如果代码行是注释,为什么它要尝试使用TLS?我用虚假的敏感数据替换了服务器名称和IP地址。如果我将端口从25更改为587并取消tls行的注释,则结果几乎相同。谢谢。
新测试,相同的结果。
Synchro建议我阅读文档。我将端口从25更改为587并添加了一行$correo->SMTPAutoTLS = true;
结果如下:
我有一个关于使用phpmailer发送电子邮件的问题。
发送邮件的代码如下:
$mail_User = "site@xxxxxxx.com";
$mail_Password = "My Password";
$mail_address = "site@xxxxxxx.com";
$mail_Name = "MyName";
$mail_Server = "222.222.222.222";
$mail_Port = 25;
function SendHTMLMail($to, $cc, $bcc, $subject, $body)
{
global $mail_User, $mail_Password, $mail_address, $mail_Name, $mail_Server, $mail_Port;
$correo = new PHPMailer;
$correo->SMTPDebug = 3; // Enable verbose debug output
$correo->SetLanguage("es", "/phpmailer/language/");
$correo->IsSMTP();
$correo->IsHTML(true);
$correo->Host = $mail_Server;
$correo->Port = $mail_Port;
$correo->SMTPAuth =true;
//$correo->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$correo->Username = $mail_User;
$correo->Password = $mail_Password;
$correo->From = $mail_address;
$correo->FromName = $mail_Name;
$correo->Subject = $subject;
$correo->Body = $body;
$dest = explode (";", $to);
for ($n=0; isset($dest[$n]); $n++) $correo->AddAddress($dest[$n]);
$dest = explode (";", $cc);
for ($n=0; isset($dest[$n]); $n++) $correo->AddCC($dest[$n]);
$dest = explode (";", $bcc);
for ($n=0; isset($dest[$n]); $n++) $correo->AddBCC($dest[$n]);
if ($correo->Send())
return "";
else {
AddLog("Correo no enviado: $correo->ErrorInfo");
echo "<br>Correo no enviado: $correo->ErrorInfo<br>";
return "Correo no enviado: $correo->ErrorInfo";
}
}
结果如下:
2016-02-24 04:58:17 Connection: opening to 222.222.222.222:25, timeout=300, options=array (
)
2016-02-24 04:58:17 Connection: opened
2016-02-24 04:58:17 SERVER -> CLIENT: 220-srv1.abcdef.com ESMTP Exim 4.86 #2 Wed, 24 Feb 2016 14:47:17 +0100
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
2016-02-24 04:58:17 CLIENT -> SERVER: EHLO www.site.com
2016-02-24 04:58:18 SERVER -> CLIENT: 250-srv1.abcdef.com Hello www.doznyk.com [181.181.181.181]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
2016-02-24 04:58:18 CLIENT -> SERVER: STARTTLS
2016-02-24 04:58:18 SERVER -> CLIENT: 220 TLS go ahead
2016-02-24 04:58:18 SMTP Error: Could not connect to SMTP host.
2016-02-24 04:58:18 CLIENT -> SERVER: QUIT
2016-02-24 04:58:19 SERVER -> CLIENT: 221 srv1.abcdef.com closing connection
2016-02-24 04:58:19 Connection: closed
2016-02-24 04:58:19 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
为什么phpmailer不能发送电子邮件?如果代码行是注释,为什么它要尝试使用TLS?我用虚假的敏感数据替换了服务器名称和IP地址。如果我将端口从25更改为587并取消tls行的注释,则结果几乎相同。谢谢。
新测试,相同的结果。
Synchro建议我阅读文档。我将端口从25更改为587并添加了一行$correo->SMTPAutoTLS = true;
$correo->SMTPAuth =true;
$correo->SMTPAutoTLS = true;
//$correo->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$correo->Username = $mail_User;
$correo->Password = $mail_Password;
结果如下:
2016-02-24 06:05:36 Connection: opening to 222.222.222.222:587, timeout=300, options=array (
)
2016-02-24 06:05:37 Connection: opened
2016-02-24 06:05:37 SERVER -> CLIENT: 220-srv1.abcdef.com ESMTP Exim 4.86 #2 Wed, 24 Feb 2016 15:54:37 +0100
220-We do not authorize the use of this system to transport unsolicited,
220 and/or bulk e-mail.
2016-02-24 06:05:37 CLIENT -> SERVER: EHLO www.myserver.com
2016-02-24 06:05:38 SERVER -> CLIENT: 250-srv1.abcdef.com Hello www.doznyk.com [181.229.171.247]
250-SIZE 52428800
250-8BITMIME
250-PIPELINING
250-AUTH PLAIN LOGIN
250-STARTTLS
250 HELP
2016-02-24 06:05:38 CLIENT -> SERVER: STARTTLS
2016-02-24 06:05:38 SERVER -> CLIENT: 220 TLS go ahead
2016-02-24 06:05:39 SMTP Error: Could not connect to SMTP host.
2016-02-24 06:05:39 CLIENT -> SERVER: QUIT
2016-02-24 06:05:39 SERVER -> CLIENT: 221 srv1.abcdef.com closing connection
2016-02-24 06:05:39 Connection: closed