Unable to send email using SMTP gmail config in codeigniter 3
11,873
Solution 1
Are you try this?
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'xxx',
'smtp_pass' => 'xxx',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
// Set to, from, message, etc.
$result = $this->email->send();
And make sure you had setting your email account with Allowing less secure apps to access your account
Solution 2
Quỳnh Nguyễn's answer worked for me too. However I think it's worth pointing out that my code fails unless I put the line
$this->email->set_newline("\r\n");
Without that line, gmail complaints about wrong user/password :|
Regards
Author by
Siddhu
Updated on June 26, 2022Comments
-
Siddhu almost 2 years
Below are my code and I refer all examples in stack overflow and codeigniter user guide. still I unable to solve this
public function send() { $config['protocol'] = 'smtp'; $config['smtp_crypto'] = 'ssl'; $config['smtp_host'] = 'smtp.gmail.com'; $config['smtp_port'] = '465'; $config['smtp_user'] = '**********@gmail.com'; $config['smtp_pass'] = '********'; $config['mailtype'] = 'html'; $config['charset'] = 'utf-8'; $config['newline'] = "\r\n"; $config['wordwrap'] = TRUE; $config['smtp_timeout'] = 30; $this->email->initialize($config); $this->email->from('[email protected]', 'admin'); $this->email->to('[email protected], [email protected]'); $this->email->subject('Registration Verification:'); $message = "Thanks for signing up! Your account has been created...!"; $this->email->message($message); if ( ! $this->email->send()) { show_error($this->email->print_debugger()); } }
How Can I solve this error ? could please favor to me