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

时间:2016-12-08 12:25:55

标签: php codeigniter email

我的codeigniter网站上有预订表格。当用户预订我收到电子邮件时,问题是我每次预订收到15封电子邮件。我收到一封电子邮件,其中包含用户提供的信息,其余部分为空白。

这是我的表格:

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

这是我的控制器功能:

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');

    }

请帮帮我。

由于

1 个答案:

答案 0 :(得分:0)

似乎,当您点击页面时,会向您发送一封电子邮件。为避免此问题,您可以检查表单是否已过帐。

实施例

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');

}