我正在使用 codeigniter 我创建了一个电子邮件功能来将电子邮件发送到特定的电子邮件 ID
public function email($email){
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://smtp.gmail.com';
$config['smtp_timeout']=5;
$config['smtp_port'] = '465';
$config['smtp_user'] = 'MyEmailID@gmail.com';
$config['smtp_pass'] = '********************';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['wordwrap'] = TRUE;
$this->load->library('email');
$this->email->initialize($config);
$this->email->from('MyEmailID@gmail.com', 'MyEmailID');
$this->email->to($email);
$this->email->subject('My Subject');
$this->email->message('My Message');
return $this->email->send();
}
这在我的本地机器上运行良好,但是当我将该代码上传到托管服务器时(我正在使用 Godaddy 托管)我我收到以下错误:
A PHP Error was encountered
Severity: Warning
Message: fsockopen(): unable to connect to ssl://smtp.gmail.com:465 (Connection refused)
Filename: libraries/Email.php
Line Number: 2020
Backtrace:
File: /home/MyDir/public_html/application/models/BasicModel.php Line: 47 Function: send
File: /home/MyDir/public_html/application/controllers/Login.php Line: 48 Function: email
File: /home/MyDir/public_html/index.php Line: 315 Function: require_once
最佳答案
使用 Tls 代替 ssl 并将端口号更改为 587 $this->email->initialize($config); $config = 数组();
//Load email library
$config['protocol'] = 'smtp';
$config['smtp_host'] = 'tls://smtp.gmail.com';
$config['smtp_port'] = '587';
$config['smtp_timeout'] = '7';
$config['smtp_user'] = 'email';
$config['smtp_pass'] = 'password';
$config['charset'] = 'utf-8';
$config['wordwrap'] = TRUE;
$config['mailtype'] = 'html';
$config['validation'] = TRUE; // bool whether to validate email or not
$this->email->set_newline("\r\n");
;
$this->email->clear(TRUE);
$this->email->to($this->input->post('email'));
$this->email->subject($row_email->email_subject);
关于php - 如何解决错误 : Message: fsockopen(): unable to connect to ssl://smtp. gmail.com:465(连接被拒绝),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41425107/