无法使用邮件类在PHP中发送邮件 [英] unable to send mail in php using mailer class
问题描述
今天我在php中做了一些邮件工作,我发现有两种方法,一种是PHP提供的简单邮件功能,另一种是我在互联网上发现的使用PHP邮件程序的方法。该网站 https://github.com/PHPMailer/PHPMailer 。问题是我运行我的程序比邮件没有被发送。让我们来看看代码
Today i was doing some mailing stuff in the php, I found that there are two methods for that one is the simple mail function provided by the Php and the second i found on the internet it was about using the PHP mailer class from the site https://github.com/PHPMailer/PHPMailer. the problem is that which i run my program than the mail is not being sent. Let's have a look at the code
<?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;
}
现在,当我运行此脚本时,出现以下错误:
Now when I run this script I get the following error:
CLIENT -> SMTP: EHLO localhost
SMTP -> ERROR: EHLO not accepted from server:
CLIENT -> SMTP: HELO localhost
注意:fwrite():发送16字节失败,errno = 10054现有连接被远程主机强制关闭。在C:\xampp\htdocs\program\mailsending1\mailsending_v1\PHPMailer-master\class.smtp.php on line 1023
Notice: fwrite(): send of 16 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host. in C:\xampp\htdocs\program\mailsending1\mailsending_v1\PHPMailer-master\class.smtp.php on line 1023
SMTP -> ERROR: HELO not accepted from server:
SMTP -> NOTICE: EOF caught while checking if connected
SMTP Connect() failed.
Mailer Error: SMTP Connect() failed.
推荐答案
首先尝试找到错误
if ($mail->Send())
{
echo "mail send sucessfully";
}
else
{
echo "sending failed";
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
将邮件正文放入邮件中
put body in your mail
$mail->Body="<!DOCTYPE html>
<html lang='en-us'>
<head>
<meta charset='utf-8'>
<title></title>
</head>
<body>
<div>
</div>
</body>
</html>";
这篇关于无法使用邮件类在PHP中发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!