I'm creating a custom module that uses PHPMailer, which has been installed in the module's vendor folder via composer.
This is the error I get:
Error: Class 'PHPMailer' not found in Drupal\multisend\Service\MailerService->__construct()
PHPMailer is being used in a service class and a PHPMailer object is being created in the service classes constructor. Here is the code:
<?php
namespace Drupal\multisend\Service;
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
class MailerService
{
private $mailer;
private $config;
private $attorney_data;
public function __construct($attorney_data)
{
$this->mailer = new PHPMailer(true);
$this->config = \Drupal::config('multisend.settings');
$this->attorney_data = $attorney_data;
}
...
I've even tried require()
on the PHPMailer class but no luck. If anyone could give any suggestions, I would appreciate it greatly.
use
statement? Also, strive to use dependency injection for your classes (nonew
statement or global container).require
should never be needed in 99% of cases. How did you install the package? It states that it’s in the modules vendor folder, but it should really be in the root vendor folder.composer require phpmailer/phpmailer
installs the package in the root vendor folder like @keven ^^ says should just be "use PHPMailer\PHPMailer\PHPMailer" if not perhas "use phpmailer\PHPMailer\PHPMailer" ??!