提问者:小点点

无法使用mailer类在php中发送邮件


今天我在php中做了一些邮件工作,我发现有两种方法,一种是php提供的简单邮件功能,另一种是在internet上发现的,它是关于使用网站上的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

注意:f写():发送16字节失败,errno=10054一个现有的连接被远程主机强制关闭。在第1023行的C:\xampp\htdocs\Program\mail sending1\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.

共2个答案

匿名用户

将SMTP端口更改为465。应该行得通

匿名用户

首先尝试此方法以查找错误

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>";