问题
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