php CodeIgniter 和 gmail 的 SMTP 错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20148607/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
SMTP error with CodeIgniter and gmail
提问by Tian Loon
I am using outlook.com with custom domain (eg, [email protected])
我正在使用带有自定义域的 Outlook.com(例如,[email protected])
I am using code igniter Email library
我正在使用代码点火器电子邮件库
Openssl is enabled
OpenSSL 已启用
Does anyone have any idea what is going on? I have tried many solutions by others' example. it doesn't work. i have check with service provider, they doesn't block the port
有谁知道发生了什么?我已经通过其他人的例子尝试了很多解决方案。它不起作用。我已与服务提供商核对,他们没有阻止端口
the config (at config/email.php)
配置(在 config/email.php)
$config['protocol']='smtp';
$config['smtp_host']='ssl://smtp.googlemail.com';
$config['smtp_port']='587';
$config['smtp_timeout']='30';
$config['smtp_user']='[email protected]';
$config['smtp_pass']='password';
$config['charset']='utf-8';
$config['newline']='\r\n';
Here is how i send the email (at controller/test.php)
这是我发送电子邮件的方式(在控制器/test.php)
$this->load->library('email');
$this->email->from('[email protected]', 'my name');
$this->email->to('[email protected]');
$this->email->subject('test title or subject');
$this->email->message('the content');
$this->email->send();
echo $this->email->print_debugger();
and i got such long error message
我收到了这么长的错误信息
A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
Filename: libraries/Email.php
Line Number: 1689
A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: Failed to enable crypto
Filename: libraries/Email.php
Line Number: 1689
A PHP Error was encountered
Severity: Warning
Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:587 (Unknown error)
Filename: libraries/Email.php
Line Number: 1689
A PHP Error was encountered
Severity: Warning
Message: fwrite() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1869
A PHP Error was encountered
Severity: Warning
Message: fwrite() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1869
A PHP Error was encountered
Severity: Warning
Message: fwrite() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1869
A PHP Error was encountered
Severity: Warning
Message: fwrite() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1869
A PHP Error was encountered
Severity: Warning
Message: fwrite() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fwrite() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1846
A PHP Error was encountered
Severity: Warning
Message: fgets() expects parameter 1 to be resource, boolean given
Filename: libraries/Email.php
Line Number: 1869
The following SMTP error was encountered: 0
Unable to send data: AUTH LOGIN
Failed to send AUTH LOGIN command. Error:
Unable to send data: MAIL FROM:
......
回答by Chococroc
As @SamV points out in a comment, the problem is this lines on system/libraries/Email:
正如@SamV 在评论中指出的那样,问题在于以下几行system/libraries/Email:
$ssl = ($this->smtp_crypto === 'ssl') ? 'ssl://' : '';
$this->_smtp_connect = fsockopen($ssl.$this->smtp_host,
$this->smtp_port,
$errno,
$errstr,
$this->smtp_timeout);
If you remove the ssl://from the smtp_host and you leave it as:
如果您ssl://从 smtp_host 中删除 并将其保留为:
$config['smtp_host']='smtp.googlemail.com';
it will work.
它会起作用。
回答by Vibin TV
Use
用
$config['smtp_port']='465';
回答by Tim
Use this:
用这个:
$config = Array(
'protocol' => 'smtp',
'smtp_host' => 'ssl://smtp.googlemail.com',
'smtp_port' => 465,
'smtp_user' => 'user', //without @gmail.com
'smtp_pass' => 'pass'
);
$this->load->library('email',$config);
Make sure you dont use the @gmail.com for smtp_user
确保您不要将@gmail.com 用于 smtp_user

