Send email via Gmail SMTP using PHPMailer and Codeigniter 4

PHPMailer is the most useful library in PHP for send secure SMTP email from server. So every project must needs this library to send email from SMTP. In this tutorial we learn how to send email using Gmail SMTP with help of PHPmailer Codeigniter  4 and fix problem while using this library. so lets start.

  1. Install PHPMailer with composer
  2. Setting in Google account for send email
  3. write code for sending email with PHPMailer

1. Install PHPMailer with composer :

You need to run following command in your project’s root directory.

2. Setting in gmail account before sending email

  1. Firstly you need to do some security settings in Gmail account so you will go in Google Account Settings.
  2. Disable 2-step-verification
  3. Go to Myaccount -> security tab
  4. Turn on “Less secure app”

Now your google account is ready to sending SMTP email

3. Write code for sending email with phpmailer

Create the controller name with Home.php under app/Controllers/Home.php



Now run your project with this command in your terminal:

Open your browser and open this link:

Thanks for visiting. If you have any problem or any of query you can contact feel free.

Add a Comment

Your email address will not be published. Required fields are marked *