Codeigniter Mail function sends mail to spam folder [duplicate]

╄→гoц情女王★ 提交于 2019-12-24 12:36:25

问题


I am using codeigniter mail function. Its sends mail perfectly. But all the time mail going to the spam folder. How can I overcome this.

Function

function msg_now(){
        $this->load->library('email');
        $this->load->library('parser');

        $config['protocol'] = 'sendmail';
        $config['wordwrap'] = TRUE;
        $config['mailtype'] = 'html';
        $this->email->initialize($config);
        $email_id='test@test.com';
        $name=$this->'test';
        $this->email->from('test@gmail.com');
        $this->email->to($email_id);

        $this->email->subject('Test subject');

        $this->email->message("<p>Lorem ipsum dummy content</p>");
        $this->email->send();
}

回答1:


    $this->load->library('parser');

    $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'google email id',
        'smtp_pass' => 'password',
        'mailtype'  => 'html',
        'charset'   => 'iso-8859-1'
    );

    $this->load->library('email', $config);
    $this->email->set_newline("\r\n");
    $this->email->from('google email id','Title'); // change it to yours
    $this->email->to(your send email id);// change it to yours
    $this->email->subject('you subject');
    $this->email->message('your message');
    if($this->email->send())
    {
        return true;
    }
    else
    {
        show_error($this->email->print_debugger());
    }



回答2:


There are many reasons for mail to go in spam, but easy solution for it is to set the headers of the mail before sending and giving it priority.

Here's how to do that in CodeIgniter. The function is set_header():

$this->email->set_header($header, $value);

also check this link for reference.

It has always worked for me.



来源:https://stackoverflow.com/questions/35424899/codeigniter-mail-function-sends-mail-to-spam-folder

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!