PHPMailer fails to send email via gmail SMTP service used by an organisation

你。 提交于 2019-12-23 04:45:25

问题


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!";
}

The organisation uses Gmail services for email.

From the code Above, I am getting following error:

Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

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

Thanks Everyone :)


回答1:


Gmail smtp settings reference

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



回答2:


try changing in your email account to yes in Allow access for less secure apps

look this https://help.crucial.com.au/hc/en-gb/articles/214180837-Enabling-Less-Secure-Apps




回答3:


Regarding https://support.google.com/a/answer/176600 Port 25 is only open on aspmx.l.google.com You should use Port 587 (TLS) or 465 (SSL).



来源:https://stackoverflow.com/questions/43019308/phpmailer-fails-to-send-email-via-gmail-smtp-service-used-by-an-organisation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!