Skip to content

Instantly share code, notes, and snippets.

@as3eem
Last active July 5, 2022 15:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save as3eem/ca61926fd81363bfec9cb8aeb0830e1a to your computer and use it in GitHub Desktop.
Save as3eem/ca61926fd81363bfec9cb8aeb0830e1a to your computer and use it in GitHub Desktop.
email from localhost via smtp server on codeigniter
//Load email library
$this->load->library('email');
//SMTP & mail configuration
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'user@gmail.com',
'smtp_pass' => 'gmail_password',
'mailtype' => 'html',
'charset' => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");
//Email content
$htmlContent = '<h1>Sending email via SMTP server</h1>';
$htmlContent .= '<p>This email has sent via SMTP server from CodeIgniter application.</p>';
$this->email->to('recipient@example.com');
$this->email->from('sender@example.com','MyWebsite');
$this->email->subject('How to send email via SMTP server in CodeIgniter');
$this->email->message($htmlContent);
//Send email
$this->email->send();
/////////////////////////////$this->load->library('encrypt');///////////to avoid spamming of mail////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
////CHANGE SETTINGS IN GOGLE ACCOUNTS/////
////MY ACCOUNT>SIGNING IN TO GOOGLE(under sign in & security)/////
////SWITCH OFF 2 STEP VERIFICATION/////
////IN CONNECTED APPS N SITES>SWITCH ONN---"ALLOW LESS SECURE APPS"----/////
@NahianAhmed
Copy link

thanks ..........

@imahtsham
Copy link

Thanks bro

@maulahaz
Copy link

maulahaz commented Nov 3, 2020

It's works. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment