PHPMailer returning no Error But Not Sending any Email(Live Server)

笑着哭i 提交于 2020-04-07 08:28:07

问题


I am using this code:

<?php
require ('PHPMailer/PHPMailerAutoload.php');
$mail = new PHPMailer;
//$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'allthingsremainhere@gmail.com';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SetFrom('youcanreply@lishup.com', 'Reply It! - LishUp');
$mail->AddAddress('techgoeshere@gmail.com', 'Tech');
$mail->Subject  = 'First PHPMailer Message';
$mail->Body     = 'Hi! This is my first e-mail sent through PHPMailer.';

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

It is returning 'Message has been Sent'.

My Email and Password is alright. That's not the problem.

In Google Account: 2Factor Authorization is turned off and 'Allow Less secure app' is turned on

I am using a Live Server hosted on Google Cloud. Please help me to solve this


回答1:


First of all, you're using an old version of PHPMailer. Get the latest.

Almost none of your code does anything because you commented out isSMTP(). That means that PHPMailer will send via PHP's mail() function, and none of your SMTP-related settings will be used. As a result, your message will not be sent through gmail, but via your local mail server instead, which will be silently accepting whatever you give it but then failing to relay it any further. If your sending domain is using gmail, it's likely that you will fail SPF checks, and your messages will never be delivered.

You can see exactly what has happened to your messages by reading your local mail server's log file, probably somewhere like /var/log/mail.log.




回答2:


here we go , first uncomment this line

//$mail->isSMTP();

to

$mail->isSMTP();

then run your code , it will attempt to login your gmail account and if less secure app is on it will send email else you will get email alert by gmail, if you got gmail alert then less secure is not on then just go and turn on it and run your code again it will work fine.



来源:https://stackoverflow.com/questions/60452453/phpmailer-returning-no-error-but-not-sending-any-emaillive-server

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