在wamp服务器上使用codeigniter发送邮件时出错

时间:2017-06-15 14:18:58

标签: php codeigniter email

我正在使用wamp服务器和最新版本的CodeIgniter。我从php.ini中取消注释extension=php_openssl.dll的行。我没有安装 AVG防病毒软件。但它不起作用。我在autoload.php中自动加载了电子邮件库

我的邮件发件人控制器:

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Testmail extends CI_Controller {

public function index()
{ 
    //configure email settings
    $config['protocol'] = 'sendmail';
    $config['smtp_host'] = 'ssl://smtp.gmail.com'; //smtp host name
    $config['smtp_port'] = '465'; //smtp port number
    $config['smtp_user'] = 'my_email@gmail.com';
    $config['smtp_pass'] = 'correct_password'; //$from_email password
    $config['mailtype'] = 'html';
    $config['charset'] = 'iso-8859-1';
    $config['wordwrap'] = TRUE;
    $config['newline'] = "\r\n"; //use double quotes
    $this->email->initialize($config);

    //send mail
    $this->email->from('nosisky@gmail.com', 'Mydomain');
    $this->email->to('nosisky@gmail.com');
    $this->email->subject('testing mail');
    $this->email->message('testing mail server class');
    $this->email->send();
    echo $this->email->print_debugger(); 
}


}

这是我打印CodeIgniter电子邮件调试程序时收到的错误消息的一部分。

A PHP Error was encountered

Severity: Warning

Message: 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: 2063

1 个答案:

答案 0 :(得分:0)

我使用下面的代码。它工作得很好。将协议更改为 smtp 。另请尝试在代码中删除或包含 ssl://

$config = array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://just127.justhost.com',
        'smtp_port' => 465,
        'smtp_user' => 'user@gmail.com',
        'smtp_pass' => 'yourpassword',
        'mailtype' => 'html',
        'charset' => 'iso-8859-1'
);