【发布时间】:2018-12-31 15:04:31
【问题描述】:
我创建了一个网站,其中包含两个联系表格,一个是预订表格,另一个是普通的“联系我们”表格。两个表单数据都将出现在 HTML 表中。问题是我收到了邮件主题为我声明的空白电子邮件(来自网站的预订,来自网站的查询)。但是当我尝试发送表单数据而不填写它时,它不允许我发送,html“必需”属性告诉“请填写此字段”。但是我收到了附件中显示的空白电子邮件 我的查看页面是
<form id="contact_form" method="post" enctype="multipart">
<div class="form-group">
<input type="text" class="form-control" name="name" value="" placeholder="Name" required>
</div>
<div class="form-group">
<input type="email" class="form-control" name="email" value="" placeholder="E-mail" required>
</div>
<div class="form-group">
<input type="tel" class="form-control" name="phone" value="" placeholder="Phone" required>
</div>
<div class="form-group">
<textarea class="form-control" name="message" rows="3" placeholder="Message"></textarea>
</div>
<button class="btn btn-default" type="submit" name="submit">
<i class="fa fa-paper-plane-o" aria-hidden="true"></i>Submit
</button>
</form>
jquery 是
<script>
$("#contact_form").on('submit', function(e)
{
var temp=0;
e.preventDefault();
var data = new FormData($(this))
$.ajax({
url: "<?php echo base_url();?>index.php/home/contact_details",
type: "POST",
dataType:'json',
data: new FormData(this),
contentType: false,
cache: true,
processData:false,
success: function(data)
{
alert("Successfully submitted");
}
});
});
</script>
我的控制器功能是
public function contact_details()
{
$data['name']=$name=$this->input->post('name');
$data['email']=$email=$this->input->post('email');
$data['phone']=$phone=$this->input->post('phone');
$data['message']=$message=$this->input->post('message');
$config = Array(
'protocol' => 'sendmail',
'smtp_host' => 'localhost',
'smtp_port' => 25,
'smtp_user' => 'SMTP Username',
'smtp_pass' => 'SMTP Password',
'smtp_timeout' => '4',
'mailtype' => 'html',
'charset' => 'iso-8859-1'
);
$message='<table border="1" width="100%">
<tr>
<td>Name</td>
<td>'.$name.'</td>
</tr>
<tr>
<td>Phone</td>
<td>'.$phone.'</td>
</tr>
<tr>
<td>Email</td>
<td>'.$email.'</td>
</tr>
<tr>
<td>Message</td>
<td>'.$message.'</td>
</tr>
</table>';
$this->email->set_mailtype("html");
$this->load->library('email', $config);
$this->email->from($email);
$this->email->to('example@example.ae');
$this->email->cc('example@example.com');
$this->email->cc('example@example.ae');
$this->email->subject('Enquiry from website');
$this->email->message($message);
$sent=$this->email->send();
$var=1;
echo $var;
}
【问题讨论】:
标签: php jquery codeigniter email