Online Forum To Support Coders With Technical Assistance - Read Write Execute

Send email using gmail in CodeIgniter

Ankit Agrawal
Ankit Agrawal
Published on June 13, 2018 · 1 min read

You can send email using gmail by using below code.


$this->load->library('email');

$aConfig = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'Your gmail email',
'smtp_pass' => 'Your gmail password',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($aConfig);
$this->email->set_mailtype("html");
$this->email->from('Your from email', 'Your from name');
$this->email->to("Your receiver email");
$this->email->bcc("Your bcc email"); // optional
$this->email->subject("Your email subject");
$this->email->message("Your email body");
if($this->email->send())
{
	echo "email sent";
}
else
{
	echo "email not sent";
}
Was this article helpful?
Ankit Agrawal

Ankit Agrawal

Author & Senior Engineer at CodeExecute

Writing practical engineering guides, debugging real-world bottlenecks, and creating free tools for developer productivity.

← Previous Article Remove public from url in laravel Next Article → How to declare a function in Javascript using constructor method?