codeigniter无法发送电子邮件

时间:2016-11-04 16:24:05

标签: php codeigniter

PHP代码:

    $from  = 'shahrushabh1996@gmail.com';
    $config = array(
            'protocol'=>'smtp',
            'smtp_host'=>'ssl://smtp.googlemail.com',
            'smtp_port'=>'465',
            'smtp_user'=>'shahrushabh1996@gmail.com',
            'smtp_pass'=>'********',
            'mailtype'=>'html',
            'charset'=>'UTF-8'
        );
    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->to($personemail);
    $this->email->from($from);
    $this->email->subject('it is a demo email by Rushabh Shah');
    $this->email->message('demo message');
    if(!$this->email->send()){
        show_error($this->email->print_debugger());
    }
    else{
        echo 'email is sent';
    }

错误:

Unable to send email using PHP mail().

请帮我解决以下错误?这种方法在不同的控制器中工作正常,但不能在这个控制器中工作如何解决它?请帮帮我。

1 个答案:

答案 0 :(得分:0)

试试这个

$config = array(
        'protocol'  => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => '465',
        'smtp_user' => 'xxxx@gmail.com',
        'smtp_pass' => 'xxxxx',
        'mailtype'  => 'html',
        'starttls'  => true,
        'newline'   => "\r\n"
    );

    $this->load->library('email', $config);

    $this->email->from('someuser@gmail.com', 'Test');
    $this->email->to('test@test.com');
    $this->email->subject('Test Email');
    $this->email->message('Hello World');

    $this->email->send();