I am newbie in CodeIgniter. May I know how to send an email in CodeIgniter via localhost? What should I put in the smtp_user
and smtp_pass
? Below is my controller code:
function Forgot_Password()
{
$this->form_validation->set_rules('Email', 'Email', 'trim|required|valid_email|callback_email_check');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('templates/header');
$this->load->view('Forgot_Password');
$this->load->view('templates/footer');
}
else
{
$this->load->library('email');
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxxxxxxxxx',
'smtp_pass' => 'xxxxxxxxxx'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('26328@siswa.unimas.my', 'Your Name');
$this->email->to('foo.900.fch@gmail.com');
//$this->email->cc('another@another-example.com');
//$this->email->bcc('them@their-example.com');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
if($this->email->send())
{
echo 'Email sent.';
}
else
{
show_error($this->email->print_debugger());
}
}
}
In config.php (config folder), I have:
$config['smtp_host'] = 'ssl://smtp.gmail.com'; // SMTP Server Address.
$config['smtp_port'] = '465'; // SMTP Port.
$config['protocol'] ='sendmail';