Reputation: 96
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 = '[email protected]';
$mail->Password = 'password';
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->SetFrom('[email protected]', 'Reply It! - LishUp');
$mail->AddAddress('[email protected]', '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
Upvotes: 0
Views: 1207
Reputation: 430
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.
Upvotes: 0
Reputation: 37810
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
.
Upvotes: 1