【问题标题】:CodeIgniter $this->input->post()CodeIgniter $this->input->post()
【发布时间】:2017-01-06 16:57:51
【问题描述】:

我的 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$to = myemail@gmail.com;`

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

【问题讨论】:

  • 兄弟尝试回应您的帖子并评论所有其他代码以检查您是否获得帖子价值
  • 在您的表单操作中 email_invoice 之后还有一件事是“/”
  • 您也可以转储整个$_POST 数组以查看您得到了什么,并知道其中是否包含email

标签: php codeigniter


【解决方案1】:

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

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

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

如果您没有收到错误,那么您就知道 $to 包含一个有效的电子邮件地址。这并不意味着邮件实际上会被递送。决定邮件是否通过的因素有很多。

【讨论】:

    【解决方案2】:

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

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

    【讨论】:

    • twistedpixel,非常感谢,但是表单仍然需要触发这个链接:
    • 但是当我设置 $to = 'myemail@gmail.com';这个链接触发了,我收到了电子邮件。它仍然无法弄清楚如何获取 $to 来获取邮件....
    • 我也试过这个,但没有运气:(, &lt;script&gt; windows.onload = function() { document.getElementById('mylink').onclick = function(){ document.getElementById('form-id').submit(); return false; }; }; &lt;/script&gt;
    • 您不需要事件处理程序。 “提交”类型的按钮将在您单击它们时提交表单。如果您需要发票编号作为 URL 末尾的参数,则只需将其添加到表单的 action 属性中的 URL。
    • 我没有运气...&表单没有提交&lt;button type="submit" name="submit" class="btn btn-info " action="&lt;?php echo base_url() ?&gt;admin/order/email_invoice/&lt;?php echo $invoice_info-&gt;invoice_no ?&gt;" &gt;
    猜你喜欢
    • 2017-07-29
    • 1970-01-01
    • 1970-01-01
    • 2014-12-07
    • 2017-04-11
    • 1970-01-01
    • 1970-01-01
    • 2012-09-04
    • 1970-01-01
    相关资源
    最近更新 更多