我想要將此表單發送到我的電子郵件地址。除非我使用CAPTCHA,否則PHP郵件表單不工作
這是我使用的PHP(它是位於http://protoolstutorial.org/cottageinn/上的表單)。我需要知道爲什麼這不是通過併發送到我的電子郵件。我從代碼中遺漏了什麼?
<?php
$your_email ='[email protected]';// <<=== 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;
}
}
?>
你是不是想從本地主機發送?像xampp? – 2013-03-22 14:27:07
爲了幫助你自己,寫下「var_dump($ errors);」之前「如果(空($錯誤))」:) :) – MyMomSaysIamSpecial 2013-03-22 14:28:49
jsut加var_dump不能修復它 – Philip 2013-03-22 14:31:54