消息SMTP connect()的未捕获异常'PHP mailer Exception'失败 [英] Uncaught exception 'PHP mailer Exception' with message SMTP connect() failed

查看:91
本文介绍了消息SMTP connect()的未捕获异常'PHP mailer Exception'失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误

致命错误:带有消息的未捕获异常'phpmailerException' 'SMTP connect()失败. 在 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting 中 C:\ xampp \ htdocs \ muhasibb \ epaper \ PHPMailer-master \ class.phpmailer.php:1465 堆栈跟踪:#0 C:\ xampp \ htdocs \ muhasibb \ epaper \ PHPMailer-master \ class.phpmailer.php(1301): PHPMailer-> smtpSend('Date:Tue,17 O ...','This is Yousaf ...')#1 C:\ xampp \ htdocs \ muhasibb \ epaper \ PHPMailer-master \ class.phpmailer.php(1181): PHPMailer-> postSend()#2 C:\ xampp \ htdocs \ muhasibb \ epaper \ 1.php(33): PHPMailer-> send()#3 {main}被抛出 C:\ xampp \ htdocs \ muhasibb \ epaper \ PHPMailer-master \ class.phpmailer.php 在1465行

Fatal error: Uncaught exception 'phpmailerException' with message 'SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting' in C:\xampp\htdocs\muhasibb\epaper\PHPMailer-master\class.phpmailer.php:1465 Stack trace: #0 C:\xampp\htdocs\muhasibb\epaper\PHPMailer-master\class.phpmailer.php(1301): PHPMailer->smtpSend('Date: Tue, 17 O...', 'This is Yousaf ...') #1 C:\xampp\htdocs\muhasibb\epaper\PHPMailer-master\class.phpmailer.php(1181): PHPMailer->postSend() #2 C:\xampp\htdocs\muhasibb\epaper\1.php(33): PHPMailer->send() #3 {main} thrown in C:\xampp\htdocs\muhasibb\epaper\PHPMailer-master\class.phpmailer.php on line 1465

我在使用代码时

<?php 
                            // Passing `true` enables exceptions

    //Server settings

    require 'PHPMailer-master/PHPMailerAutoload.php';
    $mail = new PHPMailer(true);                                // Enable verbose debug output
    $mail->isSMTP(); 
    $mail->SMTPDebug = 2;                                     // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'yousaf.farooq906@gmail.com';                 // SMTP username
    $mail->Password = '********';                           // SMTP password
    $mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587;
    $mail->Mailer = "smtp";                                    // TCP port to connect to

    //Recipients
    $mail->setFrom('yousaf.farooq906@gmail.com', 'Yousaf Farooq');
    $mail->addAddress('yousaf.farooq906@gmail.com', 'Joe User');     // Add a recipient
    $mail->addAddress('ellen@example.com');               // Name is optional


    //Attachments
        // Optional name

    //Content
    $mail->isHTML(true);                                  // Set email format to HTML
    $mail->Subject = 'Yousaf Farooq';
    $mail->Body    = 'This is Yousaf Farooq';


    if($mail->send())
    echo 'Message has been sent';
    else
    echo 'Message could not be sent.';
?>

推荐答案

此代码对我有用

$mail = new PHPMailer(true); // create a new object

我评论了这一行 //$ mail-> isSMTP(); //启用SMTP

I commented this line //$mail->isSMTP(); // enable SMTP

 $mail->SMTPDebug = 4; 
 $mail->SMTPAuth = true; // authentication enabled

您必须使用tls 587端口

You have to use tls whith port 587

 $mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for Gmail
 $mail->Host = "smtp.gmail.com";
 $mail->Port = 587; 
 $mail->Mailer = "smtp";
 $mail->isHTML(true);
 $mail->Username = "yourmail@gmail.com";
 $mail->Password = "yourpassword";
 $mail->From="yourmail@gmail.com";
 $mail->FromName="YOUR NAME";
 $mail->Subject = $subject;
 $mail->Body = $body;
 $mail->addAddress("somemail@gmail.com");

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

另外,当您使用gmail时,请转到具有帐户访问权限的应用并设置允许不太安全的应用:打开"

Also when you are using gmail you go to Apps with account access and set Allow less secure apps: ON

邮件配置

这篇关于消息SMTP connect()的未捕获异常'PHP mailer Exception'失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆