延迟使用codeigniter发送电子邮件

时间:2016-08-04 09:40:26

标签: codeigniter email smtp

我使用的是codeigniter 3.x.问题是我可以使用codeigniter电子邮件库和smtp发送电子邮件,但电子邮件仅在4-10分钟后发送。我怎样才能缩短时间差距。请给我一些建议。

        $config['protocol'] = 'smtp';
        $config['smtp_host'] = 'ssl://smtp.googlemail.com';
        $config['smtp_user'] = 'myemail';/*email goes here*/
        $config['smtp_pass'] = 'mypass'; /*email pwd goes here*/
        $config['smtp_port'] = 465; 
        $config['smtp_timeout'] = 5;
        $config['wordwrap'] = TRUE;
        $config['charset'] = 'utf-8';
        $config['priority'] = 1;
        $this->load->library('email');
        $this->email->set_mailtype("html");
        $this->load->library('parser');


        $this->email->from('my mail');
        $this->email->to('tomail');

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

2 个答案:

答案 0 :(得分:0)

首先检查错误日志和邮件服务是否正常。

然后你这个代码:

$ci = get_instance();
$ci->load->library('email');
$config['protocol'] = "smtp";
$config['smtp_host'] = "ssl://smtp.gmail.com";
$config['smtp_port'] = "465";
$config['smtp_user'] = "abc@gmail.com"; 
$config['smtp_pass'] = "yourpassword";
$config['charset'] = "utf-8";
$config['mailtype'] = "html";
$config['newline'] = "\r\n";

$ci->email->initialize($config);

$ci->email->from('abc@gmail.com', 'abc');
$list = array('xxx@gmail.com');
$ci->email->to($list);
$this->email->reply_to('my-email@gmail.com', 'Explendid Videos');
$ci->email->subject('This is an email test');
$ci->email->message('It is working. Great!');
$ci->email->send();

我希望这对你有用。

答案 1 :(得分:0)

它不是代码点火器库问题可能是你的服务器smtp连接工作缓慢。确认你是否使用linux然后尝试

$ sudo apt-get install heirloom-mailx

echo"这是消息正文并包含消息" | mailx -v -r" someone@example.com" -s"这是主题" -S smtp =" mail.example.com:587" -S smtp-use-starttls -S smtp-auth = login -S smtp-auth-user =" someone@example.com" -S smtp-auth-password =" abc123" -S ssl-verify = ignore yourfriend@gmail.com

进行更多检查 http://www.binarytides.com/linux-mail-with-smtp/

并检查它是快速还是慢速传送?