我在转到“谢谢”页面的网页上有一个表单。
但是,它没有向我的电子邮件帐户发送应有的信息。
这是HTML代码:
<form action="form.php" method="post" name="contact form">
<input class="text-input" type="text" name='name' placeholder="Name*" required ><br>
<div class="twenty-five-h-divider"></div>
<input class="text-input" type="text" name='email' placeholder="Email*" required><br>
<div class="twenty-five-h-divider"></div>
<textarea id="subject" name="subject" placeholder="Message*" class="text-input form-field pointer"></textarea>
<div class="twenty-five-h-divider"></div>
<p> <input type="checkbox" name="spambot2" value="Yes" id="spambot2" required> <label for="spambot2">Yes I am human</label></p>
<div class="twenty-five-h-divider"></div>
<input type="submit" class="submit-button pointer" value="Send Message" name='submit'>
</form>
这是PHP表单代码:
<?php
session_start();
if(!isset($_POST['submit']))
{
//This page should not be accessed directly. Please use the form.
echo "Error, please return to last page.";
}
$name = $_POST['name'];
$email = $_POST['email'];
$spambot = $_POST['spambot2'];
$subject = $_POST['subject'];
if ($spambot != 'Yes') {
$spambot = 'No';
}
//Validate first
if($spambot == 'No')
{
echo "Please go back and check the 'I'm not a Spambot' box.";
exit;
}
//Validate first
if(empty($name)||empty($email))
{
echo "Name, email and phone number are mandatory.";
exit;
}
if(IsInjected($visitor_email))
{
echo "Bad email value!";
exit;
}
$email_from = 'person@gmail.com';//<== update the email address
$email_subject = "Adam Brind Contact";
$email_body =
"Name: $name\n \n".
"Email: $email\n \n".
"Message: $subject\n \n".
$to = "person@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: thankyou.php');
// 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;
}
}
?>
以下是到实时网页的链接:adambrind.com
我需要修复表格的帮助,以便它将信息发送到电子邮件中。