このフォームを私のメールアドレスに送信しようとしています。
これが私が使用している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;
}
}
?>