简体   繁体   中英

PHPMailer error sending mail with smtp.gmail.com

After going through all the steps of phpmailer and looking around stackoverflow. Tested all the answers I could find from people that had the same problems as I do, but it doesn't work for me.

My code is simple:

<?php
require 'PHPMailer/PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->SMTPDebug = 1;                               // Enable verbose debug output

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'I entered a valid gmail';                 // SMTP username
$mail->Password = 'I entered my password(I'm not giving it to you people, I know what you can do ;) )';                           // SMTP password
$mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587;                                    // TCP port to connect to
$mail->SMTPKeepAlive = true; 
$mail->Mailer = "smtp"; 
$mail->From = 'The email its sent from';
$mail->FromName = 'Lobby desk';
$mail->addAddress(' Recipients mail ');               // Name is optional

$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

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

?>

I hope someone can point me to what is wrong with my code and why it gives the error:

SMTP connect() failed

And:

SMTP ERROR: Password command failed: 534-5.7.14 Please log in via your web browser and 534-5.7.14 then try again

I have entered the correct password for the gmail account and edited my settings to allow less secure apps.

As always, much thanks in advance to the users that take me seriously.

Please check once in your gmail account settings for permission to use this account to use as mailer. I think that may be the issue.

problem in this line

$mail->Password = 'I entered my password(I'm not giving it to you people, I know what you can do ;) )';  
                  ^                      ^^^                                                          ^

change to

$mail->Password = "I entered my password(I'm not giving it to you people, I know what you can do ;) )"; 

Basic Example using Gmail with PHPMailer

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM