问题
I'm trying to send an email in codeigniter, but something wrong and i dont know how to fix it. It success when I send in localhost, but when I upload my app into host, it cant send. This is my code
$this->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'username';
$config['smtp_pass'] = '****';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->initialize($config);
$this->email->send();
echo $this->email->print_debugger();
And this is my error when I submit an email
Failed to authenticate password. Error: 535 Incorrect authentication data
*from: 250 OK
to: 550-Please turn on SMTP Authentication in your mail client, or login to the
550-IMAP/POP3 server before sending your message. mb2d247.vdrs.net
550-(hanghieunara.com) [112.78.2.247]:51939 is not permitted to relay through
550 this server without authentication.*
The following SMTP error was encountered: 550-Please turn on SMTP Authentication in your mail client, or login to the 550-IMAP/POP3 server before sending your message.
mb2d247.vdrs.net 550-(hanghieunara.com) [112.78.2.247]:51939 is not permitted to relay through 550 this server without authentication.
回答1:
See if your email account is not active with difinições security for external access, if you need to grant access to your site's SMTP server (your email address) so you can perform authentication.
回答2:
To send smtp gmail autenticated with codeigniter
1 - Be sure if openssl in your php instalation is enabled.
2- This command is fundamental to script works: $this->email->set_newline("\r\n");
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'gmail.login@googlemail.com',
'smtp_pass' => 'your_password',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('gmail.login@googlemail.com', 'Your Name');
$this->email->to('recipient@destination.tld');
$this->email->subject(' CodeIgniter Rocks Socks ');
$this->email->message('Hello World');
if (!$this->email->send())
show_error($this->email->print_debugger());
else
echo 'Your e-mail has been sent!';
Full solution link: https://ellislab.com/forums/viewthread/84689/
来源:https://stackoverflow.com/questions/19926810/cant-send-email-from-gmail-in-codeigniter-smtp-authentication-error