我正在尝试将此表格发送到我的电子邮件地址。
这是我正在使用的 PHP(它用于位于http://protoolstutorial.org/cottageinn/上的表单)。我需要知道为什么这没有通过并发送到我的电子邮件。我从代码中遗漏了什么?
<?php
$your_email ='cottageinndrive@gmail.com';// <<=== update to your email address
session_start();
$errors = '';
$south = '';
$east = '';
$west = '';
$midwest = '';
$visitor_email = '';
if(isset($_POST['submit']))
{
$south = $_POST['south'];
$east = $_POST['east'];
$west = $_POST['west'];
$midwest = $_POST['midwest'];
$visitor_email = $_POST['email'];
///------------Do Validations-------------
if(empty($visitor_email))
{
$errors .= "\n Email is required fields. ";
}
if(IsInjected($visitor_email))
{
$errors .= "\n Bad email value!";
}
if(empty($errors))
{
//send the email
$to = $your_email;
$subject="New form submission";
$from = $your_email;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$body = "A user submitted the contact form:\n".
"South: $south\n".
"East: $east\n".
"West: $west\n".
"Midwest: $midwest\n".
"Email: $visitor_email \n".
"IP: $ip\n";
$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to, $subject, $body,$headers);
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;
}
}
?>