繁体   English   中英

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

[英]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=zh_CN

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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