【发布时间】:2013-08-13 08:54:36
【问题描述】:
今天我在php中做一些邮件,我发现有两种方法,一种是php提供的简单邮件功能,第二种是我在互联网上找到的关于使用php mailer类的方法网站https://github.com/PHPMailer/PHPMailer。问题是我运行我的程序而不是邮件没有被发送。让我们看一下代码
<?php
include 'PHPMailer-master/class.phpmailer.php';
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages,
// 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "smtp.gmail.com";
$mail->Port = 465; # or 587
$mail->IsHTML(true);
$mail->Username = "singh6@gmail.com";
$mail->Password = "88888*******";
$mail->SetFrom('singh@gmail.com');
$mail->AddAddress('sanu@gmail.com');
$mail->Subject = "Test";
$mail->Body = "hello";
$sendResult = $mail->Send();
if ($sendResult)
{
echo "Message has been sent";
}
else
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
现在,当我运行此脚本时,出现以下错误:
CLIENT -> SMTP: EHLO localhost
SMTP -> ERROR: EHLO not accepted from server:
CLIENT -> SMTP: HELO localhost
注意:fwrite(): send of 16 bytes failed with errno=10054 现有连接被远程主机强行关闭。在 C:\xampp\htdocs\program\mailsending1\mailsending_v1\PHPMailer-master\class.smtp.php 第 1023 行
SMTP -> ERROR: HELO not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connected
SMTP Connect() failed.
Mailer Error: SMTP Connect() failed.
【问题讨论】:
-
试过 ' $mail->ErrorInfo ' 得到错误?
-
将
"sending failed"替换为$mail->ErrorInfo并发布错误消息。 -
你能贴出上面建议的错误信息吗?
-
尝试在您的 php.ini 中取消注释 extension=php_openssl.dll 行