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

unable to send mail in php using mailer class(无法使用邮件程序类在 php 中发送邮件)
本文介绍了无法使用邮件程序类在 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 中发送邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Convert JSON integers and floats to strings(将JSON整数和浮点数转换为字符串)
in php how do I use preg replace to turn a url into a tinyurl(在php中,如何使用preg替换将URL转换为TinyURL)
all day appointment for ics calendar file wont work(ICS日历文件的全天约会不起作用)
trim function is giving unexpected values php(Trim函数提供了意外的值php)
Basic PDO connection to MySQL(到MySQL的基本PDO连接)
PHP number_format returns 1.00(Php number_Format返回1.00)