Skip to content

Override CodeIgniter 4 Email Class to send smtp with PHPMailer

License

Notifications You must be signed in to change notification settings

Pream-webapps/ci4phpmailer

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CodeIgniter 4 SMTP Email with PHPMailer

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

Latest Stable Version Total Downloads Latest Unstable Version License

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']   = '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.

Gmail support

I have tested with different accounts, in different environments, and got always working 🙌

About

Override CodeIgniter 4 Email Class to send smtp with PHPMailer

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • PHP 100.0%