Can not send mail through PHPMailer

寵の児 提交于 2019-12-24 05:41:11

问题


This is my php code

require("class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();  // telling the class to use SMTP
$mail->Host     = "smtp.gmail.com"; // SMTP server

$mail->From     = "example@gmail.com";
$mail->AddAddress("example@yahoo.com");

$mail->Subject  = "First PHPMailer Message";
$mail->Body     = "Hi! \n\n This is my first e-mail sent through PHPMailer.";
$mail->WordWrap = 50;

if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}

My php.ini has this mail configuration [mail function]

SMTP = smtp.gmail.com
smtp_port = 465
sendmail_from =example@gmail.com

My error is

The following From address failed: example@gmail.com Message was not sent.Mailer error: The following From address failed: example@gmail.com SMTP server error: 5.7.0 Must issue a STARTTLS command first. i1sm13250552pbv.49

please help me.thanks in advance......


回答1:


smtp.gmail.com requires that you use SSL and port 587 or 465.




回答2:


firstly be sure you have the last version of phpmailer()

download it from https://github.com/PHPMailer/PHPMailer

open class.phpmailer.php by php editor

replace all "HELO" words to "EHLO"

EHLO (not HELO) must be given by client before AUTH. (FOR GOOGLE MAIL)

it will be solved.




回答3:


try phpgmailer once http://www.thedanglybits.com/2006/10/13/update-send-email-with-php-and-gmail-hosted-for-your-domain/




回答4:


Change your host to

ssl://smtp.gmail.com:465


来源:https://stackoverflow.com/questions/10656532/can-not-send-mail-through-phpmailer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!