0

当我去发送电子邮件时,我正在尝试通过电子邮件发送一个带有单选按钮的表单。我得到的返回值只是“on”。我已正确设置名称“值”并将其绑定到 form_validation 代码,这一切似乎都“工作”,但值设置不正确或电子邮件发送不正确。代码如下。

控制器文件:

公共函数contact_email()

{
        $this->load->helper(array('form', 'url'));
        $this->load->library('form_validation');
        $this->load->library('email');

        $this->form_validation->set_rules('name', 'Name', 'required|xss_clean');
        $this->form_validation->set_rules('email', 'Email', 'required|valid_email|xss_clean');
        $this->form_validation->set_rules('phone', 'Phone', 'is_numeric|xss_clean');
        $this->form_validation->set_rules('comments', 'Comments', 'xss_clean');

        if ($this->form_validation->run() == FALSE) {

            $data["messages"] = "";
            $this->load->view('engage_header');
            $this->load->view('engage_nav');
            $this->load->view('contact/content_form', $data);
            $this->load->view('engage_footer');

        } else {

            $data["messages"] = "The Email has successfully been sent";

            $this->email->from(set_value("email"), set_value("name"));
            $this->email->to('test@test.com');

             $this->email->subject('Contact Request');

            $message  = "Name: " . $this->input->post('name') . "\n";
            $message .= "Email: " . $this->input->post('email') . "\n";
            $message .= "phone: " . $this->input->post('phone') . "\n\n";
            $message .= "Comments: " . $this->input->post('comments') . "\n";
            $message .= "Favorite Drink:" . $this->input->post('drinks') . "\n";

            $this->email->message($message);  

            $this->email->send();

            echo $this->email->print_debugger();

            $this->load->view('engage_header');
            $this->load->view('engage_nav');
            $this->load->view('contact/content_form', $data);
            $this->load->view('engage_footer');
        }   
    }

查看文件

<div class="form_wrapper">
        <div class="head_left">
        <p class="heading"><img src="/resources/css/images/mail_icon.png" width="32px" height="32px" class="mail_icon">Contact Us</p>
        </div>
        <div class="borders"></div>

        <div class="form_container_left">

        <?php echo form_open('/index.php/site/contact_email')?>
        <label for="name">Your Name:</label>
        <input type="text" name="name" id="name" required/>
        <br/>
        <br/>
        <br/>
        <label for="email">Email:</label>
        <input type="text" name="email" id="email" required/>
        <br/>
        <br/>
        <br/>
        <label for="phone">Phone:</label>
        <input type="text" name="phone" id="phone"/>
        <br/>
        <br/>
        <br/>
        <label for="messages">How Can We Help?:</label>
        <textarea rows="" cols="" id="messages" name="comments"></textarea>
        <br/>
        <br/>
        <br/>
        <input type="reset" name="Reset" id="reset_bar">
        <input type="submit" name="Submit" id="submit_bar" value="Submit"> 


        </div>
        <div class="form_container_right">
            <p  class="optional_heading">Your Favorite Drink (optional):</p>
            <div class="soda_container">
            <img src="/resources/css/images/Soda.png" width="64px" height="64px">
            <center><p id="soda_text">Soda</p></center>
            <br/>
            <center><input type="radio" name="drinks" id="soda" value="soda"></center>
            </div>
            <div class="coffee_container">
            <img src="/resources/css/images/coffee.png" width="64px" height="64px">
            <center><p id="coffee_text">Coffee</p></center>
            <br/>
            <center><input type="radio" name="drinks" id="coffee" value="coffee"></center>
            </div>
            <div class="water_container">
            <img src="/resources/css/images/water.png" width="64px" height="64px">
            <center><p id="water_text">Water</p></center>
            <br/>
            <center><input type="radio" name="drinks" id="water" value="water"></center>
            </div>
            <div class="beer_container">
            <img src="/resources/css/images/beer.png" width="64px" height="64px">
            <center><p id="beer_text">Beer</p></center>
            <br/>
            <center><input type="radio" name="drinks" id="beer" value="beer"></center>
            </div>
            <div class="wine_container">
            <img src="/resources/css/images/wine.png" width="64px" height="64px">
            <center><p id="wine_text">Wine</p></center>
            <br/>
            <center><input type="radio" name="drinks" id="wine" value="wine"></center>
            </div>
        </div>  
        <?php echo form_close()?>
4

1 回答 1

0

为了通过电子邮件发送单选按钮值,它们首先必须通过set_radio在 value 参数中声明嵌套来设置。像这样

<input type="radio" name="drinks" id="water" value="water" <?=set_radio('drinks','water') ?>>

有很多方法可以将这些信息召回给你的“控制器”,我只是用了一个简单的方法$this->input->post('$variable')

这就是我将其称为消息的方式,并且对我有用。

    $message  = "Name: " . $this->input->post('name') . "\n";
    $message .= "Email: " . $this->input->post('email') . "\n";
    $message .= "Phone: " . $this->input->post('phone') . "\n\n";
    $message .= "Favorite Drink: " . $this->input->post('drinks') . "\n";
    $message .= "Comments: " . $this->input->post('comments') . "\n";

视图中设置的名称“值”必须与控制器$this->input->post('')参数中传递的值相关。

感谢大家对此的帮助!!迪伦

于 2012-08-29T21:43:38.910 回答