CodeIgniter Sending Email

codeigniter

CodeIgniter is a PHP framework for building web applications. To send an email using CodeIgniter, you can use the built-in email library.

To use the email library, you will first need to load it in your controller:

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

Next, you can configure the email settings, such as the email protocol, server details, and email address details.

$config = array(
  'protocol' => 'smtp',
  'smtp_host' => 'ssl://smtp.googlemail.com',
  'smtp_port' => 465,
  'smtp_user' => '[email protected]',
  'smtp_pass' => 'your_email_password',
  'mailtype' => 'html',
  'charset' => 'iso-8859-1'
);
$this->email->initialize($config);

Next, you can set the email options and recipient:

$this->email->from('[email protected]', 'Your Name');
$this->email->to('[email protected]');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');

Finally, you can send the email using the send() function:

$this->email->send();

You can also check for errors by using the print_debugger() function:

if (!$this->email->send()) {
  show_error($this->email->print_debugger());
}