0

今天我在php中做一些邮件,我发现有两种方法,一种是Php提供的简单邮件功能,第二种是我在互联网上发现它是关于使用来自站点https的PHP邮件程序类://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.
4

2 回答 2

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>";
于 2013-08-12T05:56:44.323 回答
0

将 SMTP 端口更改为 465。它应该可以工作

于 2013-08-12T05:53:33.997 回答