PHP MAILER error autoload file

﹥>﹥吖頭↗ 提交于 2019-12-24 11:37:40

问题


i have a problem with php mailer . So on the tutorials he talks about the autoload file but when I download the folder phpmailer this file is not in , do I have to create it ?

so I still try with the file phpmailer.php in the folder src but that puts me error , here is the mistake :

Fatal error: Class 'PHPMailer' not found in C:\wamp64\www\site ajft\contact.php on line 14

here is my code:

    <?php
use League\OAuth2\Client\Grant\RefreshToken;
ini_set("display_errors", 1); 
error_reporting(E_ALL);

 $msg ="";
 if(isset($_POST['submit'])) {
require 'phpmailer/src/PHPMailer.php';

    function sendmail($to, $from, $fromname, $tel , $body) {
    *(line 14)  $mail = new PHPMailer ;
        $mail->setFrom($from, $fromname);
        $mail->addAddress($to);
        $mail->Subject = 'Contact Form - Email';
        $mail->Body = $body;
        //$mail->isHTML(isHTML: false);


        return $mail->send();
    }

    $name = $_POST['nom'];
    $email = $_POST['mail'];
    $tel = $_POST['objet'];
    $body = $_POST['message'];

    if (sendmail('Myemail@lf.com', $email, $name , $tel, $body)) {
            $msg = 'email envoyé';
        } else
            $msg = 'email non envoyé';

    }

    ?>

if anyone can tell me what to do to fix this problem, thanks in advance


回答1:


you are missing important stuff. Also remove require 'phpmailer/src/PHPMailer.php';

autoload.php is created by composer. PHPMailer no longer has its own autoloader because composer makes a much better job of it. If you don't want to use composer, you can load the files manually as described in the readme.

Composer way:

  <?php
    // Import PHPMailer classes into the global namespace
    // These must be at the top of your script, not inside a function
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;

    //Load composer's autoloader
    require 'vendor/autoload.php';

Manual Way:

<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';

Consider using their suggested php script.



来源:https://stackoverflow.com/questions/48241899/php-mailer-error-autoload-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!