从gmail发送带有CodeIgniter email()库的邮件(在Localhost中)不起作用

时间:2013-12-18 00:20:53

标签: php codeigniter email smtp

我已将codeIgniter email()设置为从我的Google帐户发送电子邮件,但错误。它不起作用,它说无法连接到服务器或服务器方没有响应。

我在php.ini中启用(取消注释)这些扩展名:

extension=php_sockets.dll
extension=php_openssl.dll

以下是我的CI配置:

$configs = array(
        'protocol'=>'smtp',
        'smtp_host'=>'ssl://smtp.gmail.com',
        'smtp_user'=>'cgmaster.iran@gmail.com',
        'smtp_pass'=>"PASSWORD",
        'smtp_port'=>'456'
        );
        $this->load->library("email", $configs);
        $this->email->set_newline("\r\n");
        $this->email->to("mostafatalebi@rocketmail.com");
        $this->email->from("cgmaster.iran@gmail.com", "Mostafa Talebi");
        $this->email->subject("This is bloody amazing.");
        $this->email->message("Body of the Message");
        if($this->email->send())
        {
            echo "Done!";   
        }
        else
        {
            echo $this->email->print_debugger();    
        }

这是我得到的第一行错误:

The following SMTP error was encountered: 10060 A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. 

1 个答案:

答案 0 :(得分:4)

您使用的是哪个版本的CI?如果它是2.1.4,则配置数组中存在差异。试试这个:

$configs = array(
    'protocol'  =>  'smtp',
    'smtp_host' =>  'ssl://smtp.gmail.com',
    'smtp_user' =>  'cgmaster.iran@gmail.com',
    'smtp_pass' =>  'PASSWORD',
    'smtp_port' =>  '465'
);