PHPMailer install without Composer

后端 未结 5 1578
旧巷少年郎
旧巷少年郎 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: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.

提交回复
热议问题