【发布时间】:2020-06-14 07:18:19
【问题描述】:
据我了解,如果您在根目录中包含 composer.json 文件并且不包含供应商文件,那么 Composer 将自动处理 JSON 指令中的库。
composer.json 文件是 PHPMailer Github 上当前的 51 行 json 文件,它位于我的 EB 根文件夹中,带有 /public 和 .ebextensions
然后我有这个 PHP 脚本 (public/phphead.php),从 AWS 文档复制
// 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;
// If necessary, modify the path in the require statement below to refer to the
// location of your Composer autoload.php file.
require '../vendor/autoload.php';
// requiring /vendor/autoload.php would throw a fatal error and so I presume this is where composer creates the vendor dir. no more fatal errors have been thrown and I have been looking to confirm this is the right location but I have only the lack of errors to make me think composer is found and working...
// ....
$mail = new PHPMailer(); //LINE 64 as per error log
EB 的错误日志输出:
PHP 致命错误:未捕获错误:类 'PHPMailer\PHPMailer\PHPMailer' 未在 /var/app/current/public/phpHead.php:64\n堆栈跟踪:\n#0 /var/app/current/public/index.php(3): include()\n#1 {main}\n 抛出 /var/app/current/public/phpHead.php 在第 64 行
我正在使用的composer.json(与PHPMailer 的composer.json 文件相同,取自GitHub):
{ "name": "phpmailer/phpmailer", "type": "library", "description": "PHPMailer is a full-featured email creation and transfer class for PHP", "authors": [ { "name": "Marcus Bointon", "email": "phpmailer@synchromedia.co.uk" }, { "name": "Jim Jagielski", "email": "jimjag@gmail.com" }, { "name": "Andy Prevost", "email": "codeworxtech@users.sourceforge.net" }, { "name": "Brent R. Matzelle" } ], "require": { "php": ">=5.5.0", "ext-ctype": "*", "ext-filter": "*" }, "require-dev": { "friendsofphp/php-cs-fixer": "^2.2", "phpunit/phpunit": "^4.8 || ^5.7", "doctrine/annotations": "^1.2" }, "suggest": { "psr/log": "For optional PSR-3 debug logging", "league/oauth2-google": "Needed for Google XOAUTH2 authentication", "hayageek/oauth2-yahoo": "Needed for Yahoo XOAUTH2 authentication", "stevenmaguire/oauth2-microsoft": "Needed for Microsoft XOAUTH2 authentication", "ext-mbstring": "Needed to send email in multibyte encoding charset", "symfony/polyfill-mbstring": "To support UTF-8 if the Mbstring PHP extension is not enabled (^1.2)" }, "autoload": { "psr-4": { "PHPMailer\\PHPMailer\\": "src/" } }, "autoload-dev": { "psr-4": { "PHPMailer\\Test\\": "test/" } }, "license": "LGPL-2.1-only" }
【问题讨论】:
-
这看起来就像您没有运行
composer install时发生的情况。我不知道 EB 应该如何处理这个问题,但问题肯定出在那里,而不是在你的代码中。 -
尝试这样使用 PHPMailer\PHPMailer\PHPMailer 而不是 PHPMailer
-
@Synchro - 谢谢,这是我的感觉...我正在尝试在没有 CLI 的情况下执行此操作,有没有办法检查 composer 是否已安装/正在安装?
-
@Dlk 这不是我的吗?如果你的意思是 new PHPMailer\PHPMailer\PHPMailer();然后我试过了(没有“使用”)
标签: php amazon-web-services composer-php amazon-elastic-beanstalk