今天我在php中做了一些邮件,我发现有两种方法,一种是Php提供的简单邮件功能,第二种是我在互联网上找到的,它是关于使用PHP邮件程序来自网站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():发送16个字节失败,errno = 10054远程主机强制关闭现有连接。在第1023行的C:\ xampp \ htdocs \ program \ mailsending1 \ mailsending_v1 \ PHPMailer-master \ class.smtp.php
SMTP -> ERROR: HELO not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connected
SMTP Connect() failed.
Mailer Error: SMTP Connect() failed.
答案 0 :(得分:0)
将SMTP端口更改为465.它应该可以正常工作
答案 1 :(得分:0)
首先尝试这样来查找错误
if ($mail->Send())
{
echo "mail send sucessfully";
}
else
{
echo "sending failed";
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
将身体放入您的邮件
$mail->Body="<!DOCTYPE html>
<html lang='en-us'>
<head>
<meta charset='utf-8'>
<title></title>
</head>
<body>
<div>
</div>
</body>
</html>";