无法使用 Google Apps 帐户与 PHPMailer 发送电子邮件
请注意,我使用的是 Google Apps 帐户,而不是 Gmail 帐户。我正在尝试使用我的 google apps 帐户和 php 简单地发送电子邮件。我可以使用端口 587 主机 smtp.googlemail.com 并启用 SSL 在 .net 应用程序中发送电子邮件。用户名是我的完整电子邮件地址。
require_once('PHPMailer_v5.1\class.phpmailer.php');
try {
$mail = new PHPMailer();
$mail->Mailer = 'smtp';
$mail->SMTPSecure = 'tls';
$mail->Host = $host;
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = $from;
$mail->Password = $password;
$mail->AddAddress($to, $to_name);
$mail->From = $from;
$mail->FromName = $from_name;
$mail->Subject = $subject;
$mail->MsgHTML($body);
$mail->IsHTML(true);
$mail->Send();
} catch (phpmailerException $e) {
echo $e->errorMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
还没能让它发挥作用,但我已经尝试了几种不同的变体。
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
// Error: Could not connect to SMTP host. This is expected as this isn't supported anymore.
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Takes forever, then I get "this stream does not support SSL/crypto PHPMailer_v5.1\class.smtp.php"
我不在乎如何,但我需要在这里使用 gmail 发送电子邮件。它可以与此库或不同的库一起。
Please note that I'm using a google apps account, NOT a gmail account. I'm trying to simply send an email using my google apps account with php. I am able to send an email in a .net application using the port 587 host smtp.googlemail.com and SSL enabled. The username is my full email address.
require_once('PHPMailer_v5.1\class.phpmailer.php');
try {
$mail = new PHPMailer();
$mail->Mailer = 'smtp';
$mail->SMTPSecure = 'tls';
$mail->Host = $host;
$mail->Port = 587;
$mail->SMTPAuth = true;
$mail->Username = $from;
$mail->Password = $password;
$mail->AddAddress($to, $to_name);
$mail->From = $from;
$mail->FromName = $from_name;
$mail->Subject = $subject;
$mail->MsgHTML($body);
$mail->IsHTML(true);
$mail->Send();
} catch (phpmailerException $e) {
echo $e->errorMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
Haven't been able to get this to work, but I've tried several different variations of this.
$mail->SMTPSecure = 'ssl';
$mail->Port = 465;
// Error: Could not connect to SMTP host. This is expected as this isn't supported anymore.
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
// Takes forever, then I get "this stream does not support SSL/crypto PHPMailer_v5.1\class.smtp.php"
I don't care how, but I need to send an email using gmail here. It can be with this library or a different one.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这是我们在网站其他地方使用的,效果很好。
编辑另外 - 我们已经不再使用 PHPMailer 并开始使用 SwiftMailer,它也适用于 gmail (http://www.swiftmailer.org/wikidocs/v3/connections/smtp)
This is what we use elsewhere on our website and it works fine.
Edit Also - We have moved away from PHPMailer and have started using SwiftMailer, which also works with gmail (http://www.swiftmailer.org/wikidocs/v3/connections/smtp)