简体   繁体   English

消息SMTP connect()的未捕获异常'PHP mailer Exception'失败

[英]Uncaught exception 'PHP mailer Exception' with message SMTP connect() failed

I am getting this error 我收到此错误

Fatal error: Uncaught exception 'phpmailerException' with message 'SMTP connect() failed. 致命错误:消息“ SMTP connect()”未捕获的异常“ phpmailerException”失败。 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 https://github.com/PHPMailer/PHPMailer/wiki/在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 ()在第1465行的C:\\ xampp \\ htdocs \\ muhasibb \\ epaper \\ PHPMailer-master \\ class.phpmailer.php中抛出#3 {main}

while i am using code 当我使用代码时

<?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.';
?>

try setting your 尝试设置您的

$mail->SMTPSecure

to

$mail->SMTPSecure = 'tls';

Also, create app password for your google account and use it in exchange for your password in $mail->Password . 另外,为您的Google帐户创建应用密码,并用它来代替$mail->Password

This code worked for me 这段代码对我有用

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

I commented this line //$mail->isSMTP(); 我评论了这一行// $ mail-> isSMTP(); // enable SMTP //启用SMTP

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

You have to use tls whith port 587 您必须使用tls和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";
 }

Also when you are using gmail you go to Apps with account access and set Allow less secure apps: ON 另外,当您使用gmail时,请转到具有帐户访问权限的应用并设置“允许不太安全的应用”:

GMAIL CONFIGURATION 邮件配置

If working in localhost, 如果在本地主机上工作,

In php.ini: remove the semicolon in front of "sendmail_from = postmaster@localhost" and restart xampp. 在php.ini中:删除“ sendmail_from = postmaster @ localhost”前面的分号,然后重新启动xampp。

In gmail account: in the security settings, turn on "Allow less secure apps". 在gmail帐户中:在安全设置中,打开“允许安全程度较低的应用”。

And finally in PHP script: add two functions: "date_default_timezone_set('Etc/UTC')" "gethostbyname('ssl://smtp.gmail.com')" as a value for " $mail->Host" 最后在PHP脚本中:添加两个函数:“ date_default_timezone_set('Etc / UTC')”“ gethostbyname('ssl://smtp.gmail.com')”作为“ $ mail-> Host”的值

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 SMTP connect()失败的PHP邮件程序 - SMTP connect() failed PHP mailer PHP Mailer错误:无法发送消息.Mailer错误:SMTP connect()失败 - PHP Mailer error: Message could not be sent.Mailer Error: SMTP connect() failed php错误消息“未捕获的异常&#39;Exception&#39;和消息&#39;Query Failed:Array” - Php Error Message “ Uncaught exception 'Exception' with message 'Query Failed:Array” PHP Mailer 返回 PHP 致命错误:未捕获的 PHPMailer\PHPMailer\Exception:SMTP 错误:无法验证 - PHP Mailer returns PHP Fatal error: Uncaught PHPMailer\PHPMailer\Exception: SMTP Error: Could not authenticate PHP Mailer SMTP 错误:无法连接到服务器:(0) 但 SMTP 测试器工作 - PHP Mailer SMTP ERROR: Failed to connect to server: (0) but SMTP tester works 消息“未能连接到:localhost:27017”的未捕获异常“ MongoConnectionException” - Uncaught exception 'MongoConnectionException' with message 'Failed to connect to: localhost:27017 PHP 邮件程序返回错误 PHPMailer\PHPMailer\Exception:SMTP 错误:以下收件人失败: - PHP mailer returning an error PHPMailer\PHPMailer\Exception: SMTP Error: The following recipients failed: 邮件无法发送.Mailer错误:SMTP连接()失败 - Message could not be sent.Mailer Error: SMTP connect() failed 邮件未发送。邮件程序错误:SMTP 连接()失败 - Message was not sent.Mailer error: SMTP connect() failed SMTP Connect() 失败。 邮件未发送。邮件程序错误:SMTP Connect() 失败 - SMTP Connect() failed. Message was not sent.Mailer error: SMTP Connect() failed
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM