PHPMailer无法通过组织使用的gmail SMTP服务发送电子邮件 [英] PHPMailer fails to send email via gmail SMTP service used by an organisation

查看:180
本文介绍了PHPMailer无法通过组织使用的gmail SMTP服务发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从平台发送电子邮件,以便每次成功注册。我正在使用PHPMailer,这是我的代码:

I am trying to send Emails from the Platform for every successful registration. I am using PHPMailer and this is my code:

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet = 'UTF-8';

$mail->Host       = "smtp.gmail.com";
$mail->SMTPDebug  = 0;
$mail->SMTPAuth   = true;
$mail->Port       = 25;
$mail->Username   = "<gmail login id>";
$mail->Password   = "<something>";

$mail->setFrom('<subdomain>.<organisation domain>', '<org name>');
$mail->addAddress($email);
$mail->Subject  = 'First PHPMailer Message';
$mail->Body = 'Hi! This is Test Message.';
if (!$mail->send()) {
        echo "Mailer Error: " . $mail->ErrorInfo;
} else {
        echo "Message sent!";
}

组织使用Gmail服务进行电子邮件。

The organisation uses Gmail services for email.

从代码上面我收到以下错误:

From the code Above, I am getting following error:


Mailer错误:SMTP connect()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

这是我第一次处理PHPMailer,所以请帮我在这里发现我的错误,我已经尝试过谷歌和SO的几种解决方案。但是没有一个似乎工作

This is my first time dealing with PHPMailer so please help me spot my mistake(s) here and I have tried several solutions from google and SO.. But none seems to work

感谢大家:)

推荐答案

Gmail smtp settings reference

$mail->setFrom('from@example.com', 'Mailer');
$mail->SMTPSecure = 'tls';
$mail->Port = 587;   

这篇关于PHPMailer无法通过组织使用的gmail SMTP服务发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆