如何在不使用作曲家的情况下将外部库安装到magento2?

时间:2018-10-08 01:26:21

标签: php magento composer-php phpmailer magento2

我想将phpmailer库添加到magento 2,因此我遵循以下答案What is the simplest way to use an external php library in a custom magento 2 module?,并且在localhost上一切正常。 但是当我尝试运行

composer require phpmailer/phpmailer 

在服务器上,我收到以下错误

Fatal error : out of memory 

我认为发生这种情况是因为我的服务器上没有足够的内存。

那么有没有其他方法可以不使用作曲家将phpmailer库添加到magento2?

2 个答案:

答案 0 :(得分:3)

实际上,我找到了解决此问题的方法:

1-在自定义模块文件夹的目录中添加phpmailer库文件夹
2-在阻止文件中添加以下内容

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';

并使用$ mail = new PHPMailer();

有关更多信息,https://github.com/PHPMailer/PHPMailer#installation--loading

答案 1 :(得分:0)

您可以在以下命令的帮助下设置memory_limit来执行作曲器:

php -d memory_limit=1000M /usr/local/bin/composer require phpmailer/phpmailer