当我尝试从 发送电子邮件时localhost
,一切正常。但是当我将我的应用程序上传到服务器时,电子邮件功能不再起作用了!我使用 Gmail 帐户。
这是我的config/email.php
文件:
$config['useragent'] = 'CodeIgniter';
$config['protocol'] = 'smtp';
$config['mailpath'] = '/usr/sbin/sendmail';
$config['smtp_host'] = 'ssl://smtp.googlemail.com';
$config['smtp_user'] = 'myemail@gmail.com';
$config['smtp_pass'] = 'my_password';
$config['smtp_port'] = 465;
$config['smtp_timeout'] = 80;
$config['wordwrap'] = TRUE;
$config['wrapchars'] = 76;
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['validate'] = FALSE;
$config['priority'] = 3;
$config['crlf'] = "\r\n";
$config['newline'] = "\r\n";
$config['bcc_batch_mode'] = FALSE;
$config['bcc_batch_size'] = 200;
$config['sender_name'] = 'Name';
$config['from_email'] = 'myemail@gmail.com';
$config['to_email'] = 'myemail@gmail.com';
$config['email_subject'] = 'Email Subject';
这就是我在控制器中发送电子邮件的方式:
$this->load->library('email');
$this->email->from($this->config->item('from_email'), $this->config->item('sender_name'));
$this->email->to($this->config->item('to_email'));
$this->email->subject($this->config->item('email_subject'));
$this->email->message($string);
if (!$this->email->send())
{
$data['success'] = FALSE;
}
else
{
$data['success'] = TRUE;
}
$this->_example_output('layouts/sendemail_confirm.php', $data);
这是我收到的错误:
遇到 PHP 错误
严重性:警告
消息:fsockopen() [function.fsockopen]:无法连接到 ssl://smtp.googlemail.com:465(连接被拒绝)
文件名:库/Email.php
行号:1689
遇到 PHP 错误
严重性:警告
消息:fwrite() 期望参数 1 是资源,给定的布尔值
文件名:库/Email.php
行号:1846
遇到 PHP 错误
严重性:警告
消息:fgets() 期望参数 1 是资源,给定的布尔值
文件名:库/Email.php
行号:1869