SMTP connect()失败。 PHPMailer(GMAIL)

时间:2016-11-16 08:09:16

标签: php email gmail phpmailer mailer

您好我在localhost中使用php邮件程序创建发送到电子邮件的代码 但我有一个问题,这个错误是:邮件程序错误:SMTP连接()失败。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

这是我的代码

<?php 
require_once('mailer/class.phpmailer.php');
require_once('mailer/PHPMailerAutoload.php');

        $from_email      = "gumay0838@gmail.com";
        $from_email_pwd  = "qwerty147";
        $from_email_name = "Gumay";
        $to_email        = "bedhoel.inc@gmail.com";

$mail             = new PHPMailer();
$body             = 'Hello World';
$body             = eregi_replace("[\]",'',$body);                  

$mail->IsSMTP();                                         // telling the class to use SMTP
$mail->SMTPAuth   = true;                                // enable SMTP authentication
$mail->SMTPSecure = "tls";                               // sets the prefix to the servier
$mail->Host       = "smtp.gmail.com";                    // sets GMAIL as the SMTP server
$mail->Port       = 587;                                 // set the SMTP port for the GMAIL server
$mail->Username   = $from_email;                         // GMAIL username
$mail->Password   = $from_email_pwd;                     // GMAIL password

$mail->SetFrom($from_email, $from_email_name);

$mail->Subject    = "Testing Mail";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$mail->AddAddress($to_email, $from_email);

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
   ?>

注意:

我已经活跃了 php.ini中的extension = php_openssl.dll

并且已经重启我的xampp并且已经将我的Gmail设置为允许安全性较低的应用:开启

0 个答案:

没有答案