我开始学习PHP,因此没有足够的能力阅读下面这些类型的报告并找到解决方案。我非常感谢您寻求解决方案。
我正在尝试配置PHPMailer。我在本地主机上取得了成功,这是我得到的成功信息。 (对不起,这里有点文字)
2016-04-21 15:41:57 CLIENT -> SERVER: EHLO localhost
2016-04-21 15:41:57 CLIENT -> SERVER: STARTTLS
2016-04-21 15:41:59 CLIENT -> SERVER: EHLO localhost
2016-04-21 15:41:59 CLIENT -> SERVER: AUTH LOGIN
2016-04-21 15:41:59 CLIENT -> SERVER: Y29udGFjdEBsZWFybmluZ2xpa2UuY29t
2016-04-21 15:41:59 CLIENT -> SERVER: TWFpbHBhc3Mz
2016-04-21 15:42:00 CLIENT -> SERVER: MAIL FROM:
2016-04-21 15:42:00 CLIENT -> SERVER: RCPT TO:
2016-04-21 15:42:04 CLIENT -> SERVER: DATA
2016-04-21 15:42:04 CLIENT -> SERVER: Date: Thu, 21 Apr 2016 17:41:56 +0200
2016-04-21 15:42:04 CLIENT -> SERVER: To: Mohan
2016-04-21 15:42:04 CLIENT -> SERVER: From: John Carter
2016-04-21 15:42:04 CLIENT -> SERVER: Subject: Subject Text
2016-04-21 15:42:04 CLIENT -> SERVER: Message-ID:
2016-04-21 15:42:04 CLIENT -> SERVER: X-Mailer: PHPMailer 5.2.13 (https://github.com/PHPMailer/PHPMailer)
2016-04-21 15:42:04 CLIENT -> SERVER: MIME-Version: 1.0
2016-04-21 15:42:04 CLIENT -> SERVER: Content-Type: multipart/alternative;
2016-04-21 15:42:04 CLIENT -> SERVER: boundary="b1_c1586352cd93247ad0e4bb5925de3337"
2016-04-21 15:42:04 CLIENT -> SERVER: Content-Transfer-Encoding: 8bit
2016-04-21 15:42:04 CLIENT -> SERVER:
2016-04-21 15:42:04 CLIENT -> SERVER: This is a multi-part message in MIME format.
2016-04-21 15:42:04 CLIENT -> SERVER:
2016-04-21 15:42:04 CLIENT -> SERVER: --b1_c1586352cd93247ad0e4bb5925de3337
2016-04-21 15:42:04 CLIENT -> SERVER: Content-Type: text/plain; charset=us-ascii
2016-04-21 15:42:04 CLIENT -> SERVER: 2016-04-21 15:42:04 CLIENT -> SERVER: This is the plain text version of the email content
2016-04-21 15:42:04 CLIENT -> SERVER:
2016-04-21 15:42:04 CLIENT -> SERVER:
2016-04-21 15:42:04 CLIENT -> SERVER: --b1_c1586352cd93247ad0e4bb5925de3337
2016-04-21 15:42:04 CLIENT -> SERVER: Content-Type: text/html; charset=us-ascii
2016-04-21 15:42:04 CLIENT -> SERVER:
2016-04-21 15:42:04 CLIENT -> SERVER: Mail body in HTML
2016-04-21 15:42:04 CLIENT -> SERVER:
2016-04-21 15:42:04 CLIENT -> SERVER:
2016-04-21 15:42:04 CLIENT -> SERVER:
2016-04-21 15:42:04 CLIENT -> SERVER: --b1_c1586352cd93247ad0e4bb5925de3337--
2016-04-21 15:42:04 CLIENT -> SERVER:
2016-04-21 15:42:04 CLIENT -> SERVER: .
2016-04-21 15:42:05 CLIENT -> SERVER: QUIT Message has been sent successfully
然而在真实服务器上同样给我一个错误,上面写着;
2016-04-21 15:42:10 CLIENT -> SERVER: EHLO www.mydomain.com
2016-04-21 15:42:10 CLIENT -> SERVER: STARTTLS
2016-04-21 15:42:10 SMTP Error: Could not connect to SMTP host.
2016-04-21 15:42:10 CLIENT -> SERVER: QUIT
2016-04-21 15:42:10 CLIENT -> SERVER: EHLO www.mydomain.com
2016-04-21 15:42:10 CLIENT -> SERVER: STARTTLS
2016-04-21 15:42:10 SMTP Error: Could not connect to SMTP host.
2016-04-21 15:42:10 CLIENT -> SERVER: QUIT
2016-04-21 15:42:10 CLIENT -> SERVER: EHLO www.learninglike.com
2016-04-21 15:42:10 CLIENT -> SERVER: STARTTLS
2016-04-21 15:42:10 SMTP Error: Could not connect to SMTP host.
2016-04-21 15:42:10 CLIENT -> SERVER: QUIT
2016-04-21 15:42:10 SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
我使用的PHP代码如下;
<?php
require_once 'PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 1;
$mail->isSMTP();
$mail->Host = 'smtp.mydomain.com; mydomaincom.ipage.com; smtp.ipage.com';
$mail->SMTPAuth = true;
$mail->Username = "contact@mydomain.com";
$mail->Password = "password";
$mail->SMTPSecure = "tls";
$mail->Port = 25;
$mail->From = "jc@gmail.com";
$mail->FromName = "John Carter";
$mail->addAddress("mohan@gmail.com", "Mohan");
$mail->isHTML(true);
$mail->Subject = "Subject Text";
$mail->Body = "<i>Mail body in HTML</i>";
$mail->AltBody = "This is the plain text version of the email content";
if(!$mail->send())
{
echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
echo "Message has been sent successfully";
}
PS:当我将加密从TLS更改为SSL时,它甚至不能在localhost中工作。如果这有助于诊断,请注意。
答案 0 :(得分:0)
您所看到的是PHPMailer的SMTP调试输出,并且因为您的代码中有$mail->SMTPDebug = 1;
而显示它。将其设置为1会显示从脚本到邮件服务器的所有流量,但它在诊断问题时不是很有用,因为您没有看到服务器所说的内容。为了实现这一点,只需设置$mail->SMTPDebug = 2;
即可。要完全关闭它,请将其设置为0.
当你将它设置为2时,你会看到问题是什么,以及如何识别和处理它将在the PHPMailer troubleshooting guide中描述,你已经链接到的错误信息。