Code Igniter不使用SMTP发送电子邮件

时间:2011-08-25 18:27:26

标签: php email codeigniter smtp

我已经设置了这样的配置

$config = Array(
        'protocol' => 'smtp', 
        'smtp_host' => 'ssl://smtp.gmail.com', 
        'smtp_port' => '465',
        'smtp_user' => '*****@gmail.com',
        'smtp_pass' => '****'
        );

但是我无法发送那封电子邮件......它显示的错误就是这样......

A PHP Error was encountered

Severity: Warning

Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?)

Filename: libraries/Email.php

Line Number: 1673
A PHP Error was encountered

Severity: Warning

Message: fwrite(): supplied argument is not a valid stream resource

Filename: libraries/Email.php

Line Number: 1816

还有很多其他错误......

1 个答案:

答案 0 :(得分:1)

首先尝试这段代码:

$config = Array(
    'protocol' => 'smtp',
    'smtp_host' => 'ssl://smtp.googlemail.com',
    'smtp_port' => 465,
    'smtp_user' => '*****@gmail.com',
    'smtp_pass' => '****'
    'mailtype'  => 'html', 
    'charset'   => 'utf-8'
);
$this->load->library('email', $config);

// Other stuff about to,from,subject...

$result = $this->email->send();

如果它不起作用,请检查您的php.ini文件。改变这一行

;extension=php_openssl.dll

extension=php_openssl.dll