gpt4 book ai didi

PHPMailer SMTP 错误 : Could not authenticate using gmail as smtp server

转载 作者:行者123 更新时间:2023-12-05 08:28:26 26 4
gpt4 key购买 nike

我无法在 appfog 上托管的应用程序中发送电子邮件我正在使用以下代码,它在 localhost 上运行良好但在 appfog 上失败。JPhpMailer 扩展类.PhpMailer.php

                    $mailer = new JPhpMailer(true);
$mailer->IsSMTP();
$mailer->Mailer = "smtp";
//$mailer->SMTPSecure == 'tls';
$mailer->Host = 'ssl://smtp.gmail.com';
$mailer->Port = '465';
$mailer->SMTPAuth = true;
//$mailer->SMTPSecure = true;
$mailer->Username = 'me@gmail.com';
$mailer->Password = 'zzzzzzz';
$mailer->SetFrom($to['from'], $to['from_name']);
$mailer->AddAddress($to['to'],$to['to_name'] );
$mailer->Subject = $to['subject'];
$mailer->Body = $to['body'];
$mailer->Send();

这是 phpMailer 中无法执行的行`if ($tls) { 如果 (!$this->smtp->StartTLS()) { 抛出新的 phpmailerException($this->Lang('tls'));

         //We must resend HELO after tls negotiation
$this->smtp->Hello($hello);
}

$connection = true;
if ($this->SMTPAuth) {
if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
**strong text throw new phpmailerException($this->Lang('authenticate')); ** }
}
}
$index++;
if (!$connection) {
throw new phpmailerException($this->Lang('connect_host'));
}

最佳答案

下面的代码对我有用:

require("phpmailer/class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com"; // specify main and backup server
$mail->Port = 587;
$mail->Username = "myemail@gmail.com"; // SMTP username
$mail->Password = "mypass"; // SMTP password

$mail->From = "myemail@gmail.com";
$mail->FromName = "myname";
$mail->AddAddress("myaddress@gmail.com", "myname");

$mail->WordWrap = 50; // set word wrap to 50 characters
$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. <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

echo "Message has been sent";

关于PHPMailer SMTP 错误 : Could not authenticate using gmail as smtp server,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14233702/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com