【发布时间】:2019-01-04 17:05:09
【问题描述】:
我在运行代码时收到上述错误。按照 PHPMAiler Github 页面上的说明,我在 composer.json 中添加了 "phpmailer/phpmailer": "^6.0" 但 PHPMailer 似乎没有加载。
我尝试使用 $mail = new PHPMailer\PHPMailer\PHPMailer(true) 而不是 $Mail = new PHPMailer(true)。我去了 Composer IRC 频道,看看我的问题是不是出在 Composer 上。我也尝试在 require 'vendor/autoload.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';
//other code...
//Create a new PHPMailer instance
$mail = new PHPMailer(true);
我希望 PHPMailer 能够运行。我哪里做错了?
【问题讨论】:
-
你运行
composer install了吗?vendor/phpmailer中是否存在包? -
我没有运行安装。我使用了此页面上的说明。 github.com/PHPMailer/PHPMailer 。 vendor 下有一个 phpmailer 目录,它有子目录和文件。我在寻找一个特定的吗?
-
使用
composer require也会安装包,但再次运行install并没有什么坏处,所以再试一次以确保自动加载器重新生成。 -
运行 composer require 再次做到了。我不知道为什么。这在暂存时有效,但我在生产中遇到了同样的问题,并且没有多少重新安装可以修复它。还有其他想法吗?
标签: phpmailer