Codeigniter电子邮件 - 浏览器继续加载

时间:2015-02-20 11:01:38

标签: php codeigniter

我正在尝试使用codeigniter发送电子邮件。

<?php
class email_page extends CI_Controller{
    function __construct(){
        parent::__construct();
    }

    function index(){
        $config = Array(
                'protocol'=>'smtp',
                'smtp_host' => 'ssl://smtp.googlemail.com',
                'smtp_port' => '465',
                'smtp_user' => 'testmail@gmail.com',
                'smtp_pass' => 'password'
            );

        $this->load->library('email', $config);
        $this->email->set_newline('\r\n');

        $this->email->from('testmail@gmail.com','Sender name');
        $this->email->to('testmail@gmail.com');
        $this->email->subject('Test mail');
        $this->email->message('This is a test mail from codeigniter');

        if($this->email->send()){
            echo "Your mail was sent successfully!!!";
        }
        else{
            show_error($this->email->print_debugger());
        }
    }
}

页面一直在加载,不会给出任何结果。代码看起来很好。有什么错误吗?感谢

3 个答案:

答案 0 :(得分:1)

在此处更改您的帐户设置

https://www.google.com/settings/security/lesssecureapps

答案 1 :(得分:1)

我自己找到了答案。

 $this->email->set_newline('\r\n');

将上述行更改为

 $this->email->set_newline("\r\n");

我不确定这是怎么发生的。

答案 2 :(得分:0)

我发现错误,只需将端口更改为25

function test(){
    $config = Array(
            'protocol'=>'smtp',
            'smtp_host' => 'smtp.gmail.com',
            'smtp_port' => '25',
            'SMTPAuth' => true,
            'smtp_user' => 'email@gmail.com',
            'smtp_pass' => 'password'
        );

    $this->load->library('email', $config);
    //$this->email->set_newline('\r\n');

    $this->email->from('email@gmail.com','Sender name');

    $this->email->to('email@micromerger.com');
    $this->email->subject('Test mail');
    $this->email->message('This is a test mail from codeigniter');
   //print_r($this->email);exit;
    if( ! $this->email->send()){
    //print_r("234");exit;
        echo "Your mail was sent successfully!!!";
    }
    else{
    //print_r("345");exit;
        show_error($this->email->print_debugger());
    }
}