简体   繁体   中英

CodeIgniter $this->input->post()

I have this in my 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>

and i have this in my controller 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');
    }

When i click submit the email not able to sent but if i replace $to = $_POST['email']; to $to = $_POST['email']; to $to = myemail@gmail.com;`

it able to sent the email. Please help ...

You are using an anchor to submit (which does not work, it will simply go to the page without submitting the form). You need to change this:

<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>

to this:

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

I strongly suggest you validate the email address before proceeding:

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

This may help you determine if your form is constructed properly and should also protect against abuse of your form.

If you don't get an error, then you know that $to contains a valid email address. This does NOT mean that the mail will actually be delivered. There are many many many factors that determine whether mail gets through or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM