简体   繁体   English

Codeigniter电子邮件-浏览器不断加载

[英]Codeigniter email - browser keeps on loading

I am trying to send email using 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());
        }
    }
}

The page keeps on loading and does not give any result. 页面继续加载,没有任何结果。 The code looks fine to me. 代码对我来说看起来不错。 Are there any errors? 有没有错误? Thanks 谢谢

在这里更改您的帐户设置

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

I myself found the answer. 我自己找到了答案。

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

Changed the above line to 将上面的行更改为

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

I am not sure how this can happen. 我不确定这种情况如何发生。

i have found error, just change port to 25 我发现错误,只需将端口更改为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());
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM