【问题标题】:CodeIgniter send multiple emailCodeIgniter 发送多封电子邮件
【发布时间】:2016-10-07 08:27:20
【问题描述】:

我正在使用 CodeIgniter 及其默认库。每当我发送电子邮件时,它都会发送两次。有没有人有一些调试指针或提示来解决这个问题?

$this->CI->email->from($this->from, $this->company_name);
$this->CI->email->to($this->to);
$this->CI->email->subject($this->subject);

eval("\$message = \"".$this->message."\";");

$this->CI->email->message($this->message);

if($attachment != "")
{
    $attac_exp=explode(",",$attachment);

    foreach($attac_exp as $key=>$value) 
    {
        if($value != '')
        {
            $this->CI->email->attach(getcwd()."/attachments/".$value);                 
        }
    }
}

$this->CI->email->send();
$this->CI->email->clear(true);

我现在已经用 SMTP 配置了 sendmail。

如果我尝试通过命令行发送电子邮件,我只会收到一封电子邮件。据我所知,问题一定出在 CodeIgniter 上。我已经对此进行了研究。

【问题讨论】:

  • 我在 phalcon 框架中遇到了类似的问题,对于我的消息正文,我不得不暗示 ob_start() 和 ob_clean 并清除消息......在 codeigniter 中有类似的东西:send([ $auto_clear = TRUE]),也许会有所帮助
  • 谢谢丹尼斯,是的,我看到了,我已经把它放在我的代码中,但不知何故它对我不起作用
  • 显示您发送此邮件的控制器代码或型号代码,因为我认为您调用此函数两次...
  • 我在发帖前还要仔细检查这里没有多次调用这个函数

标签: php codeigniter email


【解决方案1】:

下面是示例 sn-p,它可以完美地在电子邮件中附加单个文件。请参考并相应改正。

        $config = array();
        $config['useragent'] = "CodeIgniter";
        $config['mailpath'] = "/usr/bin/sendmail"; // or "/usr/sbin/sendmail"
        $config['protocol'] = "smtp";
        $config['smtp_host'] = "localhost";
        $config['smtp_port'] = "25";
        $config['mailtype'] = 'html';
        $config['charset'] = 'utf-8';
        $config['newline'] = "\r\n";
        $config['wordwrap'] = TRUE;
        $dummyfrom='admin@mydoamin.com';
        $system_name  = "Test Company";
        $from = 'rajesh@abcd.com';
        $to ='to@abcd.com';
        $bcc = 'bcc@abcd.com';$sub="Attachment Test";
        $msg = "Please ignore this mail";
        $this->load->library('email');
        $this->email->initialize($config);
        $this->email->from($dummyfrom, $system_name);
        $this->email->reply_to($from);
        $this->email->to($to);
        $this->email->bcc($bcc);
        $this->email->subject($sub);
        $this->email->message($msg);
        $this->email->attach(APPPATH.'test.txt');
        $this->email->send();

请注意,它会从应用路径中选择文件 test.txt。 可以使用$this->email->print_debugger()查看调试。

【讨论】:

  • Ankit,同样的代码是否也发送了两次?您可以将其应用于不同的功能并检查。有了这个,你可以确定它不是发送两次的 codeigniter,但是某处的程序逻辑是错误的。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-02-08
  • 2014-06-17
  • 2016-07-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多