dousa1630 2016-12-08 12:25
浏览 6
已采纳

以codeigniter预订表格接收多封电子邮件

I have a booking form on my codeigniter website. when the user book i got an email, but the problem is that i am receiving 15 email on per booking. I got one email which has the user given information and rest are blank.

Here is my form:

    <form method="post" action="<?php echo base_url();?>Booking/booking_mail/<?php echo $row['destination']; ?>/<?php echo $row['fare']; ?>" enctype="multipart/form-data">

                       <input name="txtname" type="text" class="form-control"  required="required" />




                        <input name="textcel" type="textcel" class="form-control" required="required" />


                        <input name="txtemail" type="email"  class="form-control" name="txtemail" required="required" />



                    <textarea name="txtmessage" rows="2" cols="20" id="txtmessage" class="form-control" name="txtmessage">
</textarea>


                  <input type="submit" name="btnsendmessage" value="Send Message" id="btnsendmessage" class="btn btn-primary" />
                        </form>

and here is my controller function:

function booking_mail(){

        $txtname= $this->input->post('txtname');
        $txtcel= $this->input->post('textcel');
        $txtemail= $this->input->post('txtemail');
        $txtmessage= $this->input->post('txtmessage');
        $destination = $this->uri->segment(3);
        $fare = $this->uri->segment(4);

            $this->load->library('email');
            $this->email->from('turkishairlines.com', $txtname);
            $this->email->to('fantastictravelsuk@gmail.com');
            $this->email->subject('Turkish Airline Booking Form');

            $this->email->message(
            'Name: '.$txtname.'
            Cell No: '.$txtcel.' 
            Email: '.$txtemail.'
            Message: '.$txtmessage.'
            Destination: '.$destination.'
            Fare: '.$fare.''
         );
        $this->email->send();

            $this->load->view('thanks');

    }

Please help me out.

Thanks

  • 写回答

1条回答 默认 最新

  • douxiajia6720 2016-12-08 12:31
    关注

    It seems like, when ever you hit page, this send you an email. To avoid this issue, you can check form is posted or not.

    Example

    function booking_mail()
    {
    
        if( isset($_POST['txtemail']) )
        {
            $txtname= $this->input->post('txtname');
            $txtcel= $this->input->post('textcel');
            $txtemail= $this->input->post('txtemail');
            $txtmessage= $this->input->post('txtmessage');
            $destination = $this->uri->segment(3);
            $fare = $this->uri->segment(4);
    
                $this->load->library('email');
                $this->email->from('turkishairlines.com', $txtname);
                $this->email->to('fantastictravelsuk@gmail.com');
                $this->email->subject('Turkish Airline Booking Form');
    
                $this->email->message(
                'Name: '.$txtname.'
                Cell No: '.$txtcel.' 
                Email: '.$txtemail.'
                Message: '.$txtmessage.'
                Destination: '.$destination.'
                Fare: '.$fare.''
             );
            $this->email->send();
    
                $this->load->view('thanks');
        }
        else
            die('form is not posted');
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)