我有一个非常简单(我认为)的联系表格 - 一切都有效,但我没有收到任何邮件。这是php:
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = 'youremail@email.com'; // I've replaced youremail with my proper email here
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: Lloyd\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
这是CSS:
<div class="row contact-wrap">
<form name="sentMessage" id="contactForm" novalidate>
<div class="row control-group">
<div class="form-group col-xs-6 floating-label-form-group controls">
<label>Name *</label>
<input type="text" class="form-control" placeholder="Name" id="name" required data-validation-required-message="Please enter your name.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-6 floating-label-form-group controls">
<label>Email Address *</label>
<input type="email" class="form-control" placeholder="Email Address" id="email" required data-validation-required-message="Please enter your email address.">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-6 floating-label-form-group controls">
<label>Phone Number</label>
<input type="number" class="form-control" placeholder="Phone Number" id="phone">
<p class="help-block text-danger"></p>
</div>
</div>
<div class="row control-group">
<div class="form-group col-xs-6 floating-label-form-group controls">
<label>Message *</label>
<textarea rows="5" class="form-control" placeholder="Message" id="message" required data-validation-required-message="Please enter a message."></textarea>
<p class="help-block text-danger"></p>
</div>
</div>
<br>
<div id="success"></div>
<div class="row">
<div class="form-group col-xs-12">
<p><em>* Required fields</em></p>
<button type="submit" class="btn btn-success btn-lg">Sumbit</button>
</div>
</div>
</form>
</div>
我已经将正确的脚本放在底部,CSS链接到标题中。我是新手联系表格,所以我并不感到惊讶,这不起作用,但我已经在不同的网站上使用它,它的工作正常。