在这里,我必须编写代码,通过复选框将邮件发送到已检查的邮件ID,其值为邮件ID,但是当我将复选框值的数组传递给控制器时出现问题通过post方法它不通过coz当我打印数组时它给了我一个空数组,请帮助我。
View.php
<?php $this->load->helper('form'); ?>
<?php $attributes = array("name" => "Sendquotation","autocomplete"=>"off");
echo form_open("Sendquotation/index", $attributes);?>
<div style="max-height: calc(50vh - 110px);overflow-y: scroll;" class="panel-body col-sm-12 form-group">
<h3 align="center">Select vendor you want to mail.<br><button class="btn btn-success text-right">Send all</button></h3>
<?php
foreach($vendorlist as $row)
{
echo '<input type="checkbox" name="vendor_name[]" value="'.$row->VendorEmail.'"> <b> '.$row->VendorName.'</b><hr/><br/>';
}
?>
</div>
<div class="col-sm-4 form-group">
<button type="submit" class="btn btn-success"><i class="fa fa-file-text"> </i> Send Enquery</button>
</div>
<?php echo form_close(); ?>
Controller.php这样
<?php
class Sendquotation extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
$this->load->library(array('session', 'form_validation'));
$this->load->database();
$this->load->model('Gst_model');
$this->load->model('User_model');
}
function index()
{
$vendor_mail= $this->input->post('vendor_name');
foreach ($vendor_mail as $mail_id)
{
$data = array(
'vendormailid' => $this->input->post('mail_id')
);
$config = array(
'protocol' => 'sendmail',
'mailtype' => 'html',
'charset' => 'UTF-8',
);
$this->load->library('email', $config);
$this->email->set_newline("\r\n");
$this->email->set_mailtype("html");
$message =
'<h3>HTML MAIL</h3>';
$mail_to = "vendor@yourvendor.com";
$from_mail = 'kdk020313@gmail.com';
$from_name = 'EMERSON PVT LTD';
$reply_to = 'kdk020313@gmail.com';
$subject = "Online GSTIN Updation!";
$this->load->library('email', $config);
$this->email->from($from_mail, $from_name);
$this->email->to($data);
$this->email->cc('innovations@miisky.com');
$this->email->bcc('kdk020313@gmail.com');
$this->email->subject($subject);
$this->email->message($message);
//$this->email->attach($file);
if ($this->email->send()) {
$this->session->set_flashdata('msg','<div class="alert alert-success text-center">Mail Succesfully Sent!</div>');
//redirect('Purchase_master');
print_r($data);
}
}
}
}
答案 0 :(得分:0)
试试这个
foreach ($vendor_mail as $mail_id)
{
$data = array(
'vendormailid' =>$mail_id
);
}
您在帖子中看到有一个数组索引vendor_name,它有2个索引。您已将该数组分配给$ vendor_mail变量,这意味着$ vendor_email现在有这两个索引,您正在使用foreach()迭代该数组,那么为什么要再次从post数组中获取该索引。 foreach($ vendor_mail as $ mail_id)表示$ vendor_mail的每个索引现在都是$ mail_id ..使用它。