您好我有一个联系表单和一个PHP文件,可以在表单成功填写后处理电子邮件。出于某种原因,我没有收到此表格中的任何电子邮件。只是好奇我的代码是否正确。
HTML表格:
<form method="post" role="form" name="sentMessage" id="contactForm" action="/public_html/mail/contact_me.php" novalidate>
<div class="col-md-6">
<div class="form-group">
<input type="text" class="form-control" placeholder="Your Name *" id="name" name="name" required >
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="email" class="form-control" placeholder="Your Email *" id="email" name="email" required >
<p class="help-block text-danger"></p>
</div>
<div class="form-group">
<input type="tel" class="form-control" placeholder="Your Phone *" id="phone" name="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="Your Message *" id="message" name="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" >Send Message</button>
</div>
</form>
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 = 'will@blacart.com';
$email_subject = "Website Contact: $name";
$email_body = "You have received a contact request from tandemmetal.com.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply@tandemmetals.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply@yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
答案 0 :(得分:0)
您可以尝试使用\ r \ n而不是\ n。
$headers = "From: noreply@tandemmetals.com\r\n";
$headers .= "Reply-To: $email_address\r\n";
根据http://php.net/manual/ru/function.mail.php (万一,如果您的服务器在Windows上)。