IMG-LOGO
Home Tutorial Send email via SMTP server in CodeIgniter

Send email via SMTP server in CodeIgniter

by MH RISHAD - 20 Jan 2019
IMG

CodeIgniter Email Class provides an easy way to send email from the PHP script. Also, you can send email via SMTP server using CodeIgniter Email library.

In this tutorial, we will show how you can send HTML email via SMTP server in CodeIgniter application. The CodeIgniter email library will be used to send email using SMTP server.

             Send email via SMTP server in CodeIgniter

At first include the CodeIgniter email library. Now specify the SMTP host (smtp_host), port (smtp_port), email (smtp_user), and password (smtp_pass) in SMTP configuration ($config) as per your SMTP server.

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

//SMTP & mail configuration
$config = array(
    'protocol'  => 'smtp',
    'smtp_host' => 'ssl://smtp.ngs-it.com',
    'smtp_port' => 465,
    'smtp_user' => 'email@ngs-it.com',
    'smtp_pass' => 'email_password',
    'mailtype'  => 'html',
    'charset'   => 'utf-8'
);
$this->email->initialize($config);
$this->email->set_mailtype("html");
$this->email->set_newline("\r\n");

//Email content
$htmlContent = '

Sending email via SMTP server

'; $htmlContent .= '

This email has sent via SMTP server from CodeIgniter application.

'; $this->email->to('recipient@ngs-it.com'); $this->email->from('sender@ngs-it.com','ngs-it.com'); $this->email->subject('How to send email via SMTP server in CodeIgniter'); $this->email->message($htmlContent); //Send email $this->email->send();

Thank You 

Share:

Leave a Comment

Required fields are marked *