无法加载资源:服务器响应状态为405(方法不允许)

时间:2014-01-04 06:29:14

标签: php jquery html

这是我尝试使用php发送邮件时出现的错误 无法加载资源:服务器响应状态为405(Method Not Allowed)sendmail.php

这是表格

<form action="sendmail.php" method="post" id="contactform" >
    <div id='name-error' class='error'>Please enter your name.</div>
    <input name="name" placeholder="Name" class="form-control" type="text" id="name">
    <div id='email-error' class='error'>Please enter your valid E-mail ID.</div>
    <input name="email" placeholder="Email" class="form-control"  type="text" id="email">
    <div id='subject-error' class='error'>Please enter the subject.</div>
    <input name="subject" placeholder="Subject" class="form-control" type="text" id="subject">
    <div id='message-error' class='error'>Please enter your message.</div>
    <textarea name="message" placeholder="Message" id="message" rows="4" class="form-control"></textarea>
    <div id='mail-success' class='success'>Your message has been sent successfully.</div>
    <div id='mail-fail' class='error'> Sorry, error occured this time sending your message.</div>
    <input type="submit" value="Send Message" class="form-control" id="send-message">

</form>

这是查询

$.post("sendmail.php", $("#contactform").serialize(), function(result){
enter code here if (result == 'sent'){
$('#mail-success').slideDown(500).delay(1000).slideUp(500);
        $('#send-message').removeAttr('disabled').attr('value', 'Send Message');
} else{
$('#mail-fail').slideDown(500).delay(1000).slideUp(500);
        $('#send-message').removeAttr('disabled').attr('value', 'Send Message');
}
});
}
});

这是sendmail.php文件

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = "info@vonesoft.com";
$to = "mujtaba1004@gmail.com";
$head = "New Contact Lead - VOneSoft";
$body = "Hi , <br /><br />";

$body .= "<table border='1' cellpadding='4' cellspacing='0'>";
$body .= "<tr><td>Name </td><td> " . $name . " </td></tr>";
$body .= "<tr><td>Email </td><td> " . $email . " </td></tr>";
$body .= "<tr><td>Subject </td><td> " . $subject . " </td></tr>";
  $body .= "<tr><td>Message </td><td> " . $message . " </td></tr>";
$body .= "</table>";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

// More headers
$headers .= "From:" . $from "\r\n";

mail($to, $head, $body, $headers);
echo '1';
?>

1 个答案:

答案 0 :(得分:1)

你忘了在这里连接

  $headers .= "From:" . $from. "\r\n";
                -------------^