无法使用Gmail帐户使用php邮件发送电子邮件


Can not send email with php mailer using gmail account

在这里,我无法使用我的gmail帐户与PHPMailer发送电子邮件。示例代码:

<?php
require_once('phpmailerclass/class.phpmailer.php');
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Mailer = 'smtp';
$mail->SMTPAuth = true;
$mail->Host = 'smtp.gmail.com'; 
$mail->Port = 568;
$mail->SMTPSecure = 'ssl';
$mail->Username = "myEmail@gmail.com";
$mail->Password = "myPassword";
$mail->IsHTML(true); // if you are going to send HTML formatted emails
$mail->From = "ramalingam.p@pickzy.com";
$mail->FromName = "Ramalingam";
$mail->addAddress("yoursramalingam@gmail.com","Luu Van Minh");
$mail->Subject = "Testing PHPMailer with localhost";
$mail->Body = "Hi,<br /><br />This system is working perfectly.";
if(!$mail->Send())
{
     echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
}   
else
{
    echo "Message has been sent";
}      
?>

响应错误:

Message was not sent
PHPMailer Error: The following From address failed: myEmail@gmail.com

我还在 gmail 设置中启用了"不太安全"。但它会抛出错误。指定我的有效 gmail 发件人地址。请纠正我错的地方。

如果使用 SSL,则将端口 587 更改为 465

$mail->Port = 465;
$mail->SMTPSecure = 'ssl';

https://support.google.com/a/answer/176600?hl=en