Reputation: 11
I have config email in codeigniter
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com',
'smtp_port' => '465',
'smtp_user' => '-----',
'smtp_pass' => '-----',
'mailtype' => 'html',
'charset' => 'utf-8'
$this->load->library('email', $this->session->userdata('config'));
$this->email->from('[email protected]', 'Rtlx Team');
$this->email->to($email);
$message = "Dear ";
$this->email->subject('Rtlx Team - Account Verification');
$this->email->message($message);
$this->email->send();
$this->email->clear();
But it shows following errors:
Message: mail() [function.mail]: Failed to connect to mail server at "localhost" port 465, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()
Message: mail() expects parameter 1 to be string, array given
Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
Upvotes: 0
Views: 466
Reputation: 6272
You are loading email library incorrectly as $this->load->library('email',$this->session->userdata('config'));
.
so load it as $this->load->library('email');
and initialize it as $this->email->initialize($this->session->userdata('config'));
in below example i have taken $config
array but you can take your own configuration in session also as in question you have used. but set all option as i have set in $config
you can set it in session's variable.
full code below:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => '[email protected]', // change it to yours
'smtp_pass' => 'yourpassword', // change it to yours
'mailtype' => 'html',// it can be text or html
'wordwrap' => TRUE,
'newline' => "\r\n",
'charset' => 'utf-8',
);
$this->load->library('email');
$this->email->initialize($config);
$this->email->from('[email protected]',"Rtlx Team");
$this->email->to('[email protected]');
$this->email->subject('Subject');
$this->email->message('Sample message');
if (!$this->email->send())
{
show_error($this->email->print_debugger());
}
else
{
echo 'Your e-mail has been sent!';
}
Upvotes: 0
Reputation: 359
Go through the link http://ellislab.com/codeigniter/user-guide/libraries/email.html and your smtp settings...
Upvotes: 0