我正在努力让我的电子邮件表单能够正常工作,并且无法确定为什么它不会丢到我的电子邮件地址。当我点击提交时,我会被引导到感谢页面,好像表格已正确发送但我从未收到过该电子邮件。我不知道如何调试这个来弄清楚我做错了什么,这真的让我感到烦恼,因为我遇到了一个可疑的问题。 如果您无法从我的代码中说出我使用Foundation作为我的框架。
非常感谢任何帮助,谢谢。
这是我的HTML
<div class="section4">
<div class="row">
<div class="small-12 medium-6 columns">
<form data-abide method="post" name="myemailform" action="FormToEmail.php">
<h2>Get in Touch</h2>
<div class="row">
<div class="large-8 columns">
<label>Name <small>required</small>
<input type="text" name="name" placeholder="Your Name" required pattern="[a-zA-Z]+"/>
</label>
<small class="error">Name is required and must be a string.</small>
</div>
</div>
<div class="row">
<div class="large-8 columns">
<label>Email <small>required</small>
<input type="text" name="email" placeholder="Your Email" required/>
</label>
<small class="error">An email address is required.</small>
</div>
</div>
<div class="row">
<div class="large-8 columns">
<label>Company
<input type="text" name="company" placeholder="Your Company" />
</label>
</div>
</div>
</form>
</div>
<div class="small-12 medium-6 columns">
<h2>Don't Hesitate to Leave a Message</h2>
<div class="row">
<div class="large-12 columns">
<label>Message
<textarea name="message" placeholder="Your Message Here"></textarea>
</label>
</div>
</div>
<input type="submit" name="submit" class="submit right" value="submit" />
</div>
</div>
</div><!-- END OF SECTION4 -->
此处是我的FormToEmail.php文件
<?php
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Need to submit the form.
echo "error; you need to submit the form!";
}
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$company = $_POST['company'];
$message = $_POST['message'];
//Validate first
if(empty($name)||empty($visitor_email))
{
echo "Name and email are mandatory!";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = $visitor_email;//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
$to = "theller5567@gmail.com";//<== update the email address
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
//Send the email!
mail($to,$email_subject,$email_body,$headers);
//done. redirect to thank-you page.
header('Location: thank-you.html');
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>