doushan5245 2017-03-11 06:40
浏览 41
已采纳

通过动态生成的复选框CODEIGNITER将邮件发送到已检查的邮件ID

Here i have to write code to send mail to checked mail id's through checkbox with its value given as mail id's but problem arises while i pass the array of checkbox's value to controller via post method its not passing coz when i print the array it gives me an empty array, Please help me over this.

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>&nbsp;&nbsp;&nbsp;'.$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("
");
    $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);
        }
     }
  }
}
  • 写回答

1条回答 默认 最新

  • down2323 2017-03-11 07:17
    关注

    Try this

    foreach ($vendor_mail as $mail_id)
    {
      $data = array(
      'vendormailid' =>$mail_id                 
       );
    }
    

    You see in your post you have an array index vendor_name which has 2 indexes. You have assigned that array to $vendor_mail variable which means $vendor_email has now those 2 indexes , you are iterating that array with a foreach() so why get that index from post array again. foreach ($vendor_mail as $mail_id) means every index of $vendor_mail is now $mail_id.. use it.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥15 帮我写一个c++工程