无法使用PHPMailer发送电子邮件 [英] Cannot send email using PHPMailer
本文介绍了无法使用PHPMailer发送电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正尝试使用phpmailer发送电子邮件。这是我写的代码。
I am trying to send an email using phpmailer. This is the code that I have written.
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->Username = 'shamir.towsif@gmail.com';
$mail->Password = '*********';
$mail->Port = 25;
$mail->From = 'shamir.towsif@gmail.com';
$mail->FromName = 'Shamir Towsif';
$mail->addAddress('shamir.towsif@gmail.com', 'Shamir Towsif');
$mail->addReplyTo('shamir.towsif@gmail.com', 'Information');
$mail->isHTML(true);
$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.\n";
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo 'Message has been sent';
}
这是我得到的错误。
Message could not be sent. Mailer Error: SMTP connect() failed.
我做错了什么。 SO中的其他问题没有帮助。提前致谢。
What am I doing wrong. The other questions in SO is not helping. Thanks in advance.
推荐答案
我面临类似的问题,但我认为您应该尝试将其添加到您的代码中: p>
I am facing a similar problem, but I think you should try adding this to your code:
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
这是PHPMailer为GMail推荐的设置,您可以看到示例在他们的Github页面。
This is PHPMailer recommended settings for GMail, you can see an example in their Github page .
这篇关于无法使用PHPMailer发送电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文