我有一个联系表单需要从选择列表中选择一封电子邮件,当用户尝试发送电子邮件时,没有错误但电子邮件未被发送。
控制器代码为:
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');
}
}
这是我的查看代码:
<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>
答案 0 :(得分:0)
您的表单输入设置了ID,但没有名称。
您的控制器正在寻找按名称处理已过帐表单的值。但如果没有在输入中分配“名称”值,它将无法工作。您需要更新输入,如下所示。
<input type="text" class="form-control" placeholder="Nome" name="name" id="name" required >