我正在使用带有smtp电子邮件的ci 2.2,并且像往常一样工作,目前工作正常,但当我将我的应用程序升级到ci 3.0时,它给了我错误:
Failed to authenticate password. Error: 535 Authentication Failed
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.
现在,这是使用ci app 2.2 email code'
的代码:
function sendEmail($to,$subject,$body,$from = "Do not reply")
{
$CI =& get_instance();
$CI->load->library('email');
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.myserviceprovider.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'email@myemail.com';
$config['smtp_pass'] = 'email_password';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['mailtype'] = 'html'; // or html
$config['validation'] = TRUE; // bool whether to validate email or not
$CI->email->initialize($config);
$CI->email->from('emaily@myemail.com',$from);
$CI->email->to($to);
$CI->email->subject($subject);
$CI->email->message($body);
if($CI->email->send())
{
return true;
//echo $CI->email->print_debugger();
}
else
{
return false;
//echo $CI->email->print_debugger();
}
}
//I'm using a custom helper to send email, this is working code
//This code is not working with ci 3.0
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.myserviceprovider.com';
$config['smtp_port'] = '465';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'email@myemail.com';
$config['smtp_pass'] = 'email_password';
$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->from('email@myemail.com','FirstName LastName');
$this->email->to('to@too.com');
$this->email->subject(rand(1000,9999));
$this->email->message('body of email');
if($this->email->send())
{
echo $this->email->print_debugger();
}
else
{
echo $this->email->print_debugger();
}
This code is not working. I don't know why, using ci 3.0
。是否有我遗漏的东西,因为如果代码正在使用ci 2.2而没有问题,它也应该与其他部分一起工作。