表单电子邮件提交的POST方法存在问题


Issue with POST method for form email submission

我已经创建了一个html表单使用以下代码(在HAML):

%form#cForm{method: 'post', name:'contactForm', action: 'formEmail.php'}
  %input{type:'text', name: 'name'} Name / Business:
  %input{type: 'text', name:'email'} Your Email:
  %textarea{name: 'message'} Message:
  %input{type:'submit', value:'Send Form'}

这是php文件(formEmail.php):

<?php
header('Content-type: text/html; charset=utf-8');
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'];
$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 = 'david.w.martin@me.com';
$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 = "david.w.martin@me.com";
$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;
  }
}
?>

当我点击"提交"时,我在控制台中收到以下错误:

POST http://localhost:9000/formEmail.php [HTTP/1.1 404 Not Found 0ms]

,浏览器中出现以下消息:

Cannot POST /formEmail.php
但是,我可以直接访问文件(通过在浏览器中输入url)。

窗体位于一个模态弹出窗口(包含在Zurb Foundation框架中)。

我迷路了,请帮帮我!

尝试将http://localhost:9000/formEmail.php放入action属性中。也许这个端口被忽略了,它试图到达http://localhost/formEmail.php,这当然是一个404。