// Step 1: Load the email library in your controller or model
$this->load->library('email');
// Step 2: Configure email preferences
$config = array(
'protocol' => 'smtp',
'smtp_host' => 'your_smtp_host',
'smtp_port' => 'your_smtp_port',
'smtp_user' => 'your_smtp_username',
'smtp_pass' => 'your_smtp_password',
'mailtype' => 'html',
'charset' => 'utf-8',
'newline' => "\r\n"
);
$this->email->initialize($config);
// Step 3: Set email parameters
$this->email->from('[email protected]', 'Your Name');
$this->email->to('[email protected]');
$this->email->subject('Email Subject');
$this->email->message('Email Content');
// Step 4: Optional - Attachments (if needed)
$attachment_path = '/path/to/your/file.pdf';
$this->email->attach($attachment_path);
// Step 5: Send the email
if ($this->email->send()) {
echo 'Email sent successfully.';
} else {
echo 'Error in sending email: ' . $this->email->print_debugger();
}