简体   繁体   English

选择电子邮件的联系表

[英]Contact form with email selection

i have a contact form who need to select one email from a select list, when an user try to send an email there are no error but the email is not sended. 我有一个联系表,需要从选择列表中选择一封电子邮件,当用户尝试发送电子邮件时,没有错误,但未发送电子邮件。

The controller code is: 控制器代码为:

public function contact(){
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->library('email');

        if(isset($_POST['act']) && $_POST['act'] =="act"){
              $name = $_POST['name'];
              $email   = $_POST['email'];
              $phone = $_POST['phone'];
              $message = $_POST['message'];

              $interested = $_POST['interested'];
              if ($interested == 'info') { 
                $to = 'xxx@xxx.org';
                }
                    else if ($interested == 'job') { 
                    $to = 'xxx@xx3.com'; 
                    }
                    else if ($interested == 'project'){
                        $to = 'xxx@xxx1.it';
                    }

              $this->load->library('email');
              $this->email->from($email, $name, $phone);
              $this->email->to($to); 
              $this->email->subject($interested);
              $this->email->message($message);  
              $this->email->send();

                redirect('Welcome/index');
          }
    }

And this is my View code: 这是我的查看代码:

<div class="col-lg-12">
                <form method="post" role="form" action="<?php echo site_url('welcome/contact'); ?>">
                    <input type="hidden" name="act" value="act"/>
                    <div class="row">
                    <div class="col-md-3">
                        <div class="form-group">
                        <p> Scegli a chi inviare la mail:</p>
                        </div>
                    </div>
                        <div class="col-md-9">
                            <div class="form-group">
                            <select class="form-control m-b" id="interested" name="interested">
                                <option value="info" id="info">Info Mail</option>
                                <option value="job" id="job">Job Mail</option>
                                <option value="project" id="project">Project Mail</option>
                             </select>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <input type="text" class="form-control" placeholder="Nome" id="name" required >
                                <p class="help-block text-danger"></p>
                            </div>
                            <div class="form-group">
                                <input type="email" class="form-control" placeholder="E-mail *" id="email" required >
                                <p class="help-block text-danger"></p>
                            </div>
                            <div class="form-group">
                                <input type="tel" class="form-control" placeholder="N° telefono" id="phone" required >
                                <p class="help-block text-danger"></p>
                            </div>
                        </div>
                        <div class="col-md-6">
                            <div class="form-group">
                                <textarea class="form-control" placeholder="Inserisci qui il tuo messaggio" id="message" required ></textarea>
                                <p class="help-block text-danger"></p>
                            </div>
                        </div>
                        <div class="clearfix"></div>
                        <div class="col-lg-12 text-center">
                            <div id="success"></div>
                            <button type="submit" class="btn btn-xl">Invia</button>
                        </div>
                    </div>
                </form>
            </div>

Your form inputs have an id set, but no name. 您的表单输入有一个ID集,但没有名称。

Your controller is looking to process the posted form values by name. 您的控制器正在按名称处理过帐的表单值。 But without the "name" value assigned in the inputs it won't work. 但是,如果没有在输入中分配“名称”值,它将无法正常工作。 You need to update your inputs like below. 您需要像下面那样更新您的输入。

<input type="text" class="form-control" placeholder="Nome" name="name" id="name" required >

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM