unable to send mail in php using mailer class(无法使用邮件程序类在 php 中发送邮件)
问题描述
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
Notice: fwrite(): send of 16 bytes failed with errno=10054 An existing connection was forcibly closed by the remote host. in C:xampphtdocsprogrammailsending1mailsending_v1PHPMailer-masterclass.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.
first try this to find errors
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 中发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:无法使用邮件程序类在 php 中发送邮件


基础教程推荐
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 在PHP中根据W3C规范Unicode 2022-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 如何替换eregi() 2022-01-01