循环不适用于在Codeigniter中发送的电子邮件

时间:2019-04-10 09:23:58

标签: codeigniter

我正在使用codeigniter框架。 我已经编写了发送电子邮件的代码,如下所示:

$this->emailcomm->sendemail($data) ;

但是它在循环中。它只工作一次。发送电子邮件后不返回任何响应。

我尝试过如下操作:

for($i=0; $i<count($keyarray);$i++)
{
 $data=array(
'to' => $keyarray[$i],  
 'from' => 'test' ,
subject' => 'test Order',
'message' => ('Please see attached sales order placed ),
'attach'  =>$array[$keyarray[$i]]['pdf']
);
$this->emailcomm->sendhtml_email($data);
}

我在emailcomm库中写的如下:

function sendhtml_email($info)
{
$this->CI->email->clear();
$this->CI->email->from('reports@gmail.com','Test Reports'); 
$this->CI->email->to($this->to);
$this->CI->email->subject($this->subject);
$this->CI->email->message($this->message);
$this->CI->email->attach($path.$this->attach,'attachment');
if($this->CI->email->send())
{
$this->CI->email->clear(TRUE);
return 1;
}
}

它仅发送一次电子邮件。我需要它循环运行很多次。发送电子邮件后,它不会像上面的返回1那样给出任何输出。请给我建议。

1 个答案:

答案 0 :(得分:0)

请尝试以下操作:

for($i=0; $i<count($keyarray);$i++)
{
 $data=array(
'to' => $keyarray[$i],  
 'from' => 'test' ,
subject' => 'test Order',
'message' => '(Please see attached sales order placed )',
'attach'  =>$array[$keyarray[$i]]['pdf']
);
$this->emailcomm->sendhtml_email($data);
}

在emailcomm库中,我的写法如下:

public function sendhtml_email($info)
{
$this->CI->load->library('email');
//$this->CI->email->clear(); //No Need
$this->CI->email->from('reports@gmail.com','Test Reports'); 
$this->CI->email->to($this->to);
$this->CI->email->subject($this->subject);
$this->CI->email->message($this->message);
$this->CI->email->attach($path.$this->attach,'attachment');
if($this->CI->email->send())
{
/*$this->CI->email->clear(TRUE);
return 1;*/ //No need
}
}

参考https://www.codeigniter.com/user_guide/libraries/email.html