$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'smtp.gmail.com',
'smtp_port' => 465,
'smtp_user' => 'XXXX@XXXX.com',
'smtp_pass' => 'XXXX',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->from('xxxxx@xxx.com', 'xxxx');
$this->email->to($email);
$this->email->subject('Hi');
$this->email->message('Hi');
if($this->email->send())
{
echo 'Your email was sent.';
}
else
{
show_error($this->email->print_debugger());
}
但它显示错误消息:fsockopen():无法连接到smtp.gmail.com:465(连接被拒绝)。
我在这里看到了Sending mail with CodeIgniter using SMTP protocol not working的解决方案,但它无效,我无法找到php.ini。
答案 0 :(得分:0)
我正在使用这种方式,它对我有用:
timestamp
此代码我用于服务器端。 每次在本地或服务器中使用邮件功能时,请确保。像这样初始化:
$config = array(
'protocol' => 'smtps',
'smtp_host' => 'ssl://smtps.googlemail.com',
'smtp_user' => DONOT_EMAIL,
'smtp_pass' => EMAIL_PASSWORD,
'smtp_port' => '465',
'mailtype' => 'html',
'smtp_timeout' => '4',
'newline' => "\r\n"
);