CodeIgniter $ this-> input-> post()

时间:2017-01-06 16:57:52

标签: php codeigniter

我在order_invoice.php中有这个

   enter code here
<button type="button" class="btn btn-default" data-toggle="modal" data-target="#myModal">Email to Customer</button>

<!-- Modal -->
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">

  <!-- Modal content-->
  <div class="modal-content">
    <div class="modal-header">
      <button type="button" class="close" data-dismiss="modal">&times;     </button>

       <form  action="<?php echo base_url() ?>admin/order/email_invoice/"    method="POST" >

    <center> <input 
                               class="form-control"
                               name="email"
                               placeholder="Customer Email Address"

                            type= <?php echo form_input('email',    set_value('email', '')); ?>    /></center>

    </div>
      <div class="modal-footer">
    <a href="<?php echo base_url() ?>admin/order/email_invoice/<?php echo $invoice_info->invoice_no ?>" type="submit"  name="submit"  class="btn btn-info " >Email to Customer</a></div>


    </form>

我在我的控制器order.php

中有这个
   //sender email
        $to = $_POST['email'];
        //subject
        $subject = 'Invoice no:' . $id;
        // set view page
        $view_page = $this->load->view('admin/order/pdf_order_invoice', $data, true);
        $send_email = $this->mail->sendEmail($from, $to, $subject, $view_page);
        if ($send_email) {
            $this->message->custom_success_msg('admin/order/order_invoice/' . $id,
                'Your email has been send successfully!');
        } else {
            $this->message->custom_error_msg('admin/order/order_invoice/' . $id,
                'Sorry unable to send your email!');
        }
    }else{
             $this->message->custom_error_msg('admin/order/order_invoice/' . $id,
            'Sorry unable to send your email, without company email');
    }

当我点击提交无法发送的电子邮件但如果我将$to = $_POST['email']; to $替换为= myemail@gmail.com;`

它能够发送电子邮件。请帮忙......

2 个答案:

答案 0 :(得分:0)

您正在使用锚点提交(这不起作用,它只会在不提交表单的情况下转到页面)。你需要改变这个:

<a href="<?php echo base_url() ?>admin/order/email_invoice/<?php echo $invoice_info->invoice_no ?>" type="submit"  name="submit"  class="btn btn-info " >Email to Customer</a>

到此:

<button type="submit" name="submit" class="btn btn-info " >Email to Customer</button>

答案 1 :(得分:0)

我强烈建议您在继续之前验证电子邮件地址:

//sender email
$to = $_POST['email'];
if (!filter_var($to, FILTER_VALIDATE_EMAIL)) {
    show_error("Email was not valid");
}

这可以帮助您确定您的表单是否构造正确,还应防止滥用您的表单。

如果您没有收到错误,那么您知道$ to包含有效的电子邮件地址。这并不意味着邮件将实际交付。有许多因素决定邮件是否通过。