我试图在我的项目中使用phpmailer,但是gmail的SMTP设置似乎不正确。我以前在这里问过几个问题,但这些解决方案似乎都不适合我。
<?php
require 'PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = ''; //gmail address
$mail->Password = ''; // gmail password
$mail->From = 'user@domain.com';
$mail->FromName = 'John Doe';
$mail->AddAddress('yadayada@gmail.com', 'Nick'); // Add a recipient
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'subject';
$mail->Body = 'message body';
$mail->AltBody = 'This is a plain-text message body';
$mail->addAttachment('images/apache_pb.png');
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>发布于 2017-06-28 11:47:59
您必须已经安装了php_openssl.dll,如果您使用wampserver非常容易,搜索并应用扩展的PHP。
在本例中,请更改以下内容:
//Set the hostname of the mail server
$mail->Host = 'smtp.gmail.com';
//Set the SMTP port number - 587 for authenticated TLS, a.k.a. RFC4409 SMTP submission 465 ssl
$mail->Port = 465;
//Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'ssl';然后您收到了gmail发来的一封电子邮件,讨论如何在这里启用不安全的访问应用程序( https://www.google.com/settings/security/lesssecureapps )。
发布于 2017-08-24 12:10:32
使用
$mail->Host = 'mail.servce.com';https://stackoverflow.com/questions/44801076
复制相似问题