[英]Sending mail to checked mail id's via dynamically generated checkbox CODEIGNITER
在這里,我必須編寫代碼以通過復選框將郵件發送到已檢查的郵件ID,並將其值作為郵件ID給出,但問題是,當我通過郵寄方法將復選框的值數組傳遞給控制器時,當我打印它給我的數組時未傳遞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);
}
}
}
}
嘗試這個
foreach ($vendor_mail as $mail_id)
{
$data = array(
'vendormailid' =>$mail_id
);
}
您在帖子中看到有一個具有2個索引的數組索引vendor_name。 您已將該數組分配給$ vendor_mail變量,這意味着$ vendor_email現在具有這2個索引,您正在使用foreach()迭代該數組,所以為什么再次從post數組獲取該索引。 foreach($ vendor_mail為$ mail_id)表示$ vendor_mail的每個索引現在都是$ mail_id ..使用它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.