【问题标题】:unable to send mail in php using mailer class无法使用邮件程序类在 php 中发送邮件
【发布时间】:2013-08-13 08:54:36
【问题描述】:

今天我在php中做一些邮件,我发现有两种方法,一种是php提供的简单邮件功能,第二种是我在互联网上找到的关于使用php mailer类的方法网站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(): 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.

【问题讨论】:

  • 试过 ' $mail->ErrorInfo ' 得到错误?
  • "sending failed" 替换为$mail-&gt;ErrorInfo 并发布错误消息。
  • 你能贴出上面建议的错误信息吗?
  • 尝试在您的 php.ini 中取消注释 extension=php_openssl.dll

标签: php gmail phpmailer


【解决方案1】:

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

【讨论】:

  • 这条线是干什么用的?尝试删除此行。 $mail->Mailer="smtp";还添加一个文本正文。 $mail->Body = '测试';
  • 检查您的防火墙是否没有阻止您的传出连接。端口 465
【解决方案2】:

先试试这个找出错误

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

【讨论】:

  • 注意:fwrite(): send of 16 bytes failed with errno=10054 现有连接被远程主机强行关闭。在 C:\xampp\htdocs\program\mailsending\mail_notification\PHPMailer-master\class.smtp.php 在第 1023 行发送 failedSMTP Connect() failed.
  • 试试这个 $mail->Host = 'smtpout.secureserver.net'; $mail->端口 = '80';
  • 我添加了正文并使用了您提供的主机和端口,但我收到错误:SMTP Connect() failed.
  • 这样做 $mail->SMTPSecure = '';
  • 检查您的用户名和密码
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-01-09
  • 1970-01-01
  • 2020-04-19
  • 1970-01-01
  • 2021-02-27
  • 1970-01-01
相关资源
最近更新 更多