如何在codeignitor电子邮件中使用foreach循环发送
问题描述:
我想在codeignitor控制器中发送电子邮件。我已经使用foreach循环体内多个附件。但它不起作用。给我一些建议 这里是我的控制器功能。如何在codeignitor电子邮件中使用foreach循环发送
function emailSend($ship_item_data{
//$link = base_url();
$email ="[email protected]";
$this->load->library('email');
$config['mailtype'] = "html";
$this->email->initialize($config);
$this->email->from($email, 'GHL Sports');
$this->email->to($email);
$this->email->subject('Sold items detail');
$msg='<html>
<head>
<title>Sold item</title>
</head>
<body>
Dear GHL Sports Client.
<p>This items heas been sold.</p><ul>';
foreach($ship_item_data as $data){
$item = $data['image_name'];
$this->email->attach("sold/".$item);
$msg .= '<li>'. $item .'</li>';
}
$msg .='</u>
Please do reply to this email as it will not be monitored.
</body>
</html>';
$this->email->message($msg);
//$link = base_url();
//$this->email->attach("sold/1.jpg");
//Send mail
if($this->email->send()) {
echo "email send successfully";
}else{
echo "email not send";
}
我还在构造函数中包含电子邮件库。
$this->load->helper('path');
$this->load->library('email');
答
您需要使用$这个 - >的电子邮件 - >清除(TRUE);清除循环中设置的变量。
看看这个问题http://stackoverflow.com/questions/15090421/codeigniter-attaching-2-files-to-email-that-have-been-uploaded-from-user-form – shantanu