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.
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 = '
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
Required fields are marked *
Get all latest content delivered to your email free.