Home  >  Q&A  >  body text

Serious problem: Unable to find 'PHPMailer' class

<p><br /></p><ul> <li>I tried:<code>include_once('C:InetpubwwwrootphpPHPMailerPHPMailerAutoload.php');</code></li> </ul> <blockquote> <p>Fatal error: Class 'PHPMailer' not found on line 151 of C:Inetpubwwwrootphpindex.php</p> </blockquote> <p>I placed <code>PHPMailerAutoload.php</code> in the same directory as my script. </p> <p>Can anyone help me resolve this issue? </p>
P粉738346380P粉738346380398 days ago465

reply all(1)I'll reply

  • P粉442576165

    P粉4425761652023-08-21 14:25:01

    All answers are now outdated. Latest versions (as of February 2018) no longer have autoloading, PHPMailer should be initialized as follows:

    <?php
    
      require("/home/site/libs/PHPMailer-master/src/PHPMailer.php");
      require("/home/site/libs/PHPMailer-master/src/SMTP.php");
    
        $mail = new PHPMailer\PHPMailer\PHPMailer();
        $mail->IsSMTP(); // 启用SMTP
    
        $mail->SMTPDebug = 1; // 调试:1 = 错误和消息,2 = 仅消息
        $mail->SMTPAuth = true; // 启用身份验证
        $mail->SMTPSecure = 'ssl'; // 启用安全传输,Gmail要求
        $mail->Host = "smtp.gmail.com";
        $mail->Port = 465; // 或者587
        $mail->IsHTML(true);
        $mail->Username = "xxxxxx";
        $mail->Password = "xxxx";
        $mail->SetFrom("xxxxxx@xxxxx.com");
        $mail->Subject = "测试";
        $mail->Body = "你好";
        $mail->AddAddress("xxxxxx@xxxxx.com");
    
         if(!$mail->Send()) {
            echo "邮件发送失败:" . $mail->ErrorInfo;
         } else {
            echo "邮件已发送";
         }
    ?>

    reply
    0
  • Cancelreply