skip to Main Content

I want to add phpmailer library to magento 2 so for that i followed the following answer What is the simplest way to use an external php library in a custom magento 2 module? and everything works fine on localhost.
But when i tried to run

composer require phpmailer/phpmailer 

on server i got the following error

Fatal error : out of memory 

I think that this happens because i don’t have enough memories on my server.

So is there an alternative way to add the phpmailer library to magento2 without using composer ?

2

Answers


  1. Chosen as BEST ANSWER

    Actually I found a solution for this problem :

    1- add the phpmailer library folder in a directory whithin the custom module folder
    2- add the following in the block file

    use PHPMailerPHPMailerPHPMailer;
    use PHPMailerPHPMailerException;
    
    require 'path/to/PHPMailer/src/Exception.php';
    require 'path/to/PHPMailer/src/PHPMailer.php';
    require 'path/to/PHPMailer/src/SMTP.php';
    

    and use $mail = new PHPMailer();

    for more info https://github.com/PHPMailer/PHPMailer#installation--loading


  2. You can set memory_limit to carry out composer with the help of the following command:

    php -d memory_limit=1000M /usr/local/bin/composer require phpmailer/phpmailer
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search