PHPMailer install without Composer

后端 未结 5 1503
旧巷少年郎
旧巷少年郎 2021-01-13 15:03

Please forgive my ignorance. I am trying to install PHPMailer 6.0.1 under PHP 5.6 on Linux. My PHP installation is remote and I manage all my websites’ PHP via FTP (I typi

相关标签:
5条回答
  • 2021-01-13 15:39

    Not passable without composer....

    Warning: require(src/Exception.php): failed to open stream: No such file or directory in C:\xampp\htdocs\testtest\test.php on line 5

    Fatal error: require(): Failed opening required 'src/Exception.php' (include_path='C:\xampp\php\PEAR') in C:\xampp\htdocs\testtest\test.php on line 5

    0 讨论(0)
  • 2021-01-13 15:53

    This isn't specific to PHPMailer - it's what you need to do to use any of the myriad PHP packages that use namespaces. The PHP docs on how to use use are here.

    The short version is, you need to put namespace and use directives before any other scripting, so if you simply reverse the order of your commands, it should work:

    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\SMTP;
    use PHPMailer\PHPMailer\Exception;
    require_once 'PHPMailer/src/PHPMailer.php';
    require_once 'PHPMailer/src/SMTP.php';
    

    Incidentally, this is the order used in the example in the PHPMailer readme and all the other examples provided with PHPMailer. You may find the upgrade guide useful too.

    The PHPMailerAutoload.php file no longer exists - composer's autoloader does a much better job. PHPMailer's own composer.json file is used to resolve dependencies and flag compatibility requirements for your app's own composer file, that is, it's used to tell your project's composer file how to use PHPMailer – but is not your project's composer file itself – every package you load will have its own.

    Developing without a local PHP instance is hard work – developing on your live server is, shall we say, "discouraged"! If you can't install PHP directly, run it in a container or VM using Docker, VirtualBox or something like XAMPP that's completely self-contained.

    0 讨论(0)
  • 2021-01-13 15:53

    Modify you require, and try set like the wiki of PHPMailer says:

    <?php
    require 'PHPMailerAutoload.php';
    $mail = new PHPMailer;
    

    Link of wiki

    0 讨论(0)
  • 2021-01-13 16:00

    In version 6.02, each of the phpmailer modules contain the namespace PHPMailer\PHPMailer declaration so the following works (no autoloader needed but this routine should be in /src folder):

    include($_SERVER['DOCUMENT_ROOT'].'/path_setup.php');
    require_once ($_SERVER['DOCUMENT_ROOT'].'/php/PHPMailer/src/PHPMailer.php');
    require_once ($_SERVER['DOCUMENT_ROOT'].'/php/PHPMailer/src/SMTP.php');
    require_once ($_SERVER['DOCUMENT_ROOT'].'/php/PHPMailer/src/Exception.php');
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\SMTP;
    use PHPMailer\PHPMailer\Exception;
    $mail = new PHPMailer(true);
    
    0 讨论(0)
  • 2021-01-13 16:02

    First create a folder src and create Exception.php,PHPMailer.php,SMTP.php Liber's then we get results

    <?php
    use PHPMailer\PHPMailer\PHPMailer;
    use PHPMailer\PHPMailer\Exception;
    
    require 'src/Exception.php';
    require 'src/PHPMailer.php';
    require 'src/SMTP.php';
    
    $mail = new PHPMailer;
    $mail->isSMTP(); 
    $mail->SMTPDebug = 2; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
    $mail->Host = "smtp.gmail.com"; // use $mail->Host = gethostbyname('smtp.gmail.com'); // if your network does not support SMTP over IPv6
    $mail->Port = 587; // TLS only
    $mail->SMTPSecure = 'tls'; // ssl is depracated
    $mail->SMTPAuth = true;
    $mail->Username = '@gmail.com';
    $mail->Password = '';
    $mail->setFrom('@gmail.com', '...');
    $mail->addReplyTo('@gmail.com', ' Name');
    $mail->addAddress('@gmail.com', '...');
    $mail->Subject = 'PHPMailer GMail SMTP test';
    $mail->msgHTML("Hello test SMTP body"); //$mail->msgHTML(file_get_contents('contents.html'), __DIR__); //Read an HTML message body from an external file, convert referenced images to embedded,
    $mail->AltBody = 'HTML messaging not supported';
    // $mail->addAttachment('images/phpmailer_mini.png'); //Attach an image file
    
    if(!$mail->send()){
        echo "Mailer Error: " . $mail->ErrorInfo;
    }else{
        echo "Message sent!";
    }
    ?>*strong text*
    
    0 讨论(0)
提交回复
热议问题