Tested witj CodeIgniter 4.1.1 and PHPMailer 6.3.0
This plugin utilizes Composer for its installation and PHPMailer dependency. If you haven't already, start by installing Composer.
And are available via Composer/Packagist. Once you have Composer configured in your environment run the command line:
$ composer require nachoaguirre/ci4phpmailer
This command will write into composer.json beyond download and place this project files and PHPMailer dependencies into your vendor
folder.
Your able to send e-mail anywhere inside your CodeIgniter application.
Load the library in your controller
use Nachoaguirre\Ci4phpmailer\Libraries\Email
Then in your method, create an instance of Mail()
class:
$email = new \Nachoaguirre\Ci4phpmailer\Libraries\Email
Use the class in the same way you use the CI4 Email Class
$email = new \Nachoaguirre\Ci4phpmailer\Libraries\Email;
$config['protocol'] = 'smtp';
$config['SMTPHost'] = 'smtp.gmail.com';
$config['SMTPUser'] = 'your@gmail.com';
$config['SMTPPass'] = 'yourp4ssword';
$config['SMTPPort'] = 465;
$config['SMTPCrypto'] = 'ssl';
$email->initialize($config);
$email->setFrom('noreply@yoursite.com', 'Your Name');
$email->setTo('buddy@foo.com');
$email->setSubject('Hey dude!');
$email->setMessage('Corre que te pillo...');
$email->send();
That's all.
I have tested with different accounts, in different environments, and got always working 🙌