CodeIgniter和gmail的SMTP错误

时间:2013-11-22 15:33:40

标签: php codeigniter email gmail

我在outlook.com中使用自定义域名(例如,nono @ forexample.com)

我正在使用代码点火器电子邮件库

启用Openssl

有谁知道发生了什么事? 我已经尝试过其他人的例子。它不起作用。 我检查过服务提供商,他们没有阻止端口

配置(位于config / email.php)

$config['protocol']='smtp';
$config['smtp_host']='ssl://smtp.googlemail.com';
$config['smtp_port']='587';
$config['smtp_timeout']='30';
$config['smtp_user']='thenameidontknow@gmail.com';
$config['smtp_pass']='password';
$config['charset']='utf-8';
$config['newline']='\r\n';

以下是我发送电子邮件的方式(在controller / test.php上)

$this->load->library('email');
$this->email->from('thenameidontknow@gmail.com', 'my name');
$this->email->to('lalalala@live.com');
$this->email->subject('test title or subject');
$this->email->message('the content');
$this->email->send();
echo $this->email->print_debugger(); 

我收到如此长的错误消息

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:
......

3 个答案:

答案 0 :(得分:4)

正如@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);

如果从smtp_host中删除ssl://,则将其保留为:

$config['smtp_host']='smtp.googlemail.com';

它会起作用。

答案 1 :(得分:0)

使用

 $config['smtp_port']='465';

答案 2 :(得分:0)

使用此:

$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);

请确保您不要将@ gmail.com用于smtp_user