Skip to content

Instantly share code, notes, and snippets.

@as3eem
Last active July 5, 2022 15:13
Show Gist options
  • Select an option

  • Save as3eem/ca61926fd81363bfec9cb8aeb0830e1a to your computer and use it in GitHub Desktop.

Select an option

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
Copy Markdown

thanks ..........

@imahtsham

Copy link
Copy Markdown

Thanks bro

@maulahaz

maulahaz commented Nov 3, 2020

Copy link
Copy Markdown

It's works. Thanks

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