您好我在codeigniter工作。我想显示从输入传递到我的电子邮件html格式的所有数组。但现在只显示1个项目名称,如何显示所有项目名称。谢谢
<?php
$details = $this->transaction_detail->get_all_by_header($trans->id)->result();
foreach($details as $value)
{
echo '<input type="hidden" name="itemname" value="'. $this->item->get_info($value->item_id)->name. '">';
}
?>
收到数组并输入电子邮件功能
public function send_mail()
{
$config['newline'] = "\r\n";
$from_email = "info@xxx.com";
$to_email = $this->input->post('email');
// Only show one item only, how to show all the result array item name
$itemname = $this->input->post('itemname');
$html = "Item Name :" . $itemname . "<br>" .
//Load email library
$this->load->library('email');
$this->email->initialize($config);
$this->email->from($from_email, 'xxx.com');
$this->email->to($to_email);
$this->email->subject("xxx.com - Completed Order");
$this->email->message($html);
//Send mail
if ($this->email->send()) {
$this->session->set_flashdata("email_sent", "Email sent successfully.");
redirect(site_url('transactions'));
return true;
} else {
$this->session->set_flashdata("email_sent", "Error in sending Email.");
return false;
}
}
答案 0 :(得分:1)
我只能猜测你的应用是如何工作的,但首先,我会把你的输入变成一个数组。
echo '<input type="hidden" name="itemname[]" value="'. $this->item->get_info($value->item_id)->name. '">';
然后纠正控制器:
$html = '';
$items = $this->input->post('itemname[]');//or without square brackets
foreach ($items as $item) {
$html .= "Item Name :" . $item. "<br>" .
}