0
votes

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 = [email protected];`

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

2
bro try to echo your post and comment all other codes to check whether you get your post value - Geordy James
and one more thing remore '/' after email_invoice in your form action - Geordy James
also you can dump the whole $_POST array to see what you get, and know that is contain email or not. - Yahya

2 Answers

0
votes

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.

0
votes

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>