找不到类'PHPMailer \\ PHPMailer \\ Exception'

时间:2018-11-25 17:19:55

标签: php phpmailer

使用PHP Mailer版本6.0.6

我知道会回答类似的问题,但是我的情况有所不同。 我已经成功配置了脚本,它运行正常。我当时正在接收邮件,但突然间我没有任何变化,就开始向我抛出此错误。

错误

    [Sun Nov 25 21:49:37.852920 2018] [:error] [pid 2060:tid 780] [client ::1:59300] 
   PHP Fatal error:  Uncaught Error: Class 'PHPMailer\\PHPMailer\\Exception' not found in   E:\\TCi\\htdocs\\sdresidency\\website\\plugins\\PHPMailer\\PHPMailer.php:1920\nStack trace:\n#0  E:\\TCi\\htdocs\\sdresidency\\website\\plugins\\PHPMailer\\PHPMailer.php(1774): PHPMailer\\PHPMailer\\PHPMailer->smtpConnect(Array)\n#1   E:\\TCi\\htdocs\\sdresidency\\website\\plugins\\PHPMailer\\PHPMailer.php(1516): PHPMailer\\PHPMailer\\PHPMailer->smtpSend('Date: Sun, 25 N...', 'This is a multi...')\n#2 
E:\\TCi\\htdocs\\sdresidency\\website\\plugins\\PHPMailer\\PHPMailer.php(1352): PHPMailer\\PHPMailer\\PHPMailer->postSend()\n#3  
E:\\TCi\\htdocs\\sdresidency\\website\\newbooking.php(38): PHPMailer\\PHPMailer\\PHPMailer->send()\n#4 {main}\n  thrown in 

这是我用来发送邮件的配置

require_once "plugins/PHPMailer/PHPMailer.php";
        require_once "plugins/PHPMailer/SMTP.php";
        $mail = new PHPMailer\PHPMailer\PHPMailer();
    $mail->IsSMTP(); // enable SMTP



    //Enable SMTP debugging. 
    $mail->SMTPDebug = 0;  // debugging: 1 = errors and messages, 2 = messages only                             
    //Set PHPMailer to use SMTP.
    $mail->IsSMTP(); // enable SMTP          
    //Set SMTP host name                          
    $mail->Host = "md-in-30.webhostbox.net";
    //Set this to true if SMTP host requires authentication to send email
    $mail->SMTPAuth = true;                          
    //Provide username and password     
    $mail->Username = "<my mail id>";                 
    $mail->Password = "<my password>";                           
    //If SMTP requires TLS encryption then set it
    $mail->SMTPSecure = "tls";                           
    //Set TCP port to connect to 
    $mail->Port = 587;                                   

    $mail->From = "<my mail id>";
    $mail->FromName = "SD RESIDENCY";
    $mail->addAddress("<receive mail id>", "name");
    $mail->isHTML(true);
    $mail->Subject = "NEW RESERVATION";
    $mail->Body = $message;
    $mail->AltBody = "No HTML Support";

    if(!$mail->send()) 
    {    $_SESSION['message'] = 'SOME ERROR OCCURED, PLEASE TRY AGAIN';} 
    else 
    {    
        $_SESSION['message'] = 'BOOKING COMPLETED SUCCESSFULLY';
        header("Location: " . $_SERVER["HTTP_REFERER"]);

    }

我将html格式的邮件内容存储在$ message变量中。 我已经在这里和其他站点中尝试了所有已回答的问题,但是没有运气。任何帮助将不胜感激

1 个答案:

答案 0 :(得分:1)

  1. 尝试将require_once "plugins/PHPMailer/PHPMailer.php";替换为

require_once "./plugins/PHPMailer/PHPMailer.php";

  1. 请勿直接包含库。使用作曲家进行自动加载
    1. 安装Composer https://getcomposer.org/download/
    2. 通过Composer安装PHP Mailer。在控制台composer require phpmailer/phpmailer https://packagist.org/packages/phpmailer/phpmailer
    3. 上键入
    4. 在php文件中包含Composer的自动加载器。 require 'vendor/autoload.php';
    5. 利润。您可以非常容易地包含和使用PHP Mailer和其他库