PHP控件的HTML控件 - 错误

时间:2015-06-04 21:24:28

标签: php html email web

我想让我的联系表格通过PHP发送电子邮件。我收到错误“HTTP ERROR 405.0 - Method Not Allowed”。 “由于使用的方法(HTTP动词)无效,因此无法显示您要查找的页面。”

以下是我的HTML代码。

<div class="col-md-9 col-xs-12 forma">
    <form action="formToEmail.php" name="myemailform" method="POST">
       <input type="text" class="col-md-6 col-xs-12 name" name='name' placeholder='Name *'/>
       <input type="text" class="col-md-6 col-xs-12 Email" name='email' placeholder='Email *'/>
       <textarea type="text" class="col-md-12 col-xs-12 Message" name='message' placeholder='Message *'></textarea>
       <div class="cBtn col-xs-12">
          <input type="submit" name="submit" value="Send" />
             <ul>
                <li class="clear"><a href="#"><i class="fa fa-times"></i>clear form</a></li>
                <li class="send"><a href="#"><i class="fa fa-share"></i>Send Message</a></li>               
             </ul>
       </div>
    </form>     
</div>

这是我的PHP代码 - (它是一个免费的PHP电子邮件发件人)

<?php
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 = 'myEmail@domain.com';//<== update the email address
$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 = "myEmail@domain.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: 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;
  }
}

?> 

1 个答案:

答案 0 :(得分:0)

我知道这很愚蠢,但只是检查:我遇到问题的大多数情况是因为发件人电子邮件没有我使用的相同域名。是这样的吗?