Send email via Gmail SMTP server in CodeIgniter

Send email via Gmail SMTP server in CodeIgniter:

To use Gmail SMTP for sending email in CodeIgniter, We need to make some changes in Google account settings Option.

Follow the below steps to use Gmail SMTP Setup in CodeIgniter email library.

  • Login to your Google account.
  • Go to the Google My Account page. Click the Signing in to Google link from Sign-in & security section.

  • Scroll down the Password & sign-in method section and turn Off the 2-Step Verification.

  • Scroll down the Connected apps & sites section and turn On Allow less secure apps.


Now your Gmail account is ready to use in CodeIgniter email library as an SMTP server.

The following example code help to send HTML email in CodeIgniter using your Gmail account. You only need to specify your Gmail email address (smtp_user) and password (smtp_pass).

$from_name = "Test Email"; 
$from_email = '[email protected]'; 
$to_email = '[email protected]'; 

//Email content 
$subject = 'checking Mail2'; 
$message = 'Message : checking Mail2'; 

//Load email library 

//SMTP & mail configuration 

$config = array( 
    'protocol' => 'smtp', 
    'smtp_host' => 'ssl://', 
    'smtp_port' => 465, 
    'smtp_user' => '[email protected]', 
    'smtp_pass' => 'gmail_password', 
    'mailtype' => 'html', 
    'charset' => 'utf-8' 

$this->email->from($from_email, $from_name); 

//Send email 
   print_r('Send Successfully'); 
   echo "Error Happened"; 
   echo $this->email->print_debugger(); 

Leave a Comment