ci4phpmailer

Override CodeIgniter 4 Email Class to send smtp with PHPMailer

MIT License

Downloads
161
Stars
5
Committers
2

CodeIgniter 4 SMTP Email with PHPMailer

A simple extension of the Email Class to send SMTP with PHPMailer library.

Tested witj CodeIgniter 4.1.1 and PHPMailer 6.3.0

Install via Composer

To get this plugin via composer is the quick start.

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

Example

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']   = '[email protected]';
$config['SMTPPass']   = 'yourp4ssword';
$config['SMTPPort']   = 465;
$config['SMTPCrypto'] = 'ssl';
$email->initialize($config);

$email->setFrom('[email protected]', 'Your Name');
$email->setTo('[email protected]');

$email->setSubject('Hey dude!');
$email->setMessage('Corre que te pillo...');

$email->send(); 

That's all.

Gmail support

I have tested with different accounts, in different environments, and got always working πŸ™Œ