简体   繁体   中英

Failed to load resource: the server responded with a status of 405 (Method Not Allowed)

This is the error coming while i try to send mail using php.
Failed to load resource: the server responded with a status of 405 (Method Not Allowed) sendmail.php

this is the form

<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>

this is the query

$.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');
}
});
}
});

this is the sendmail.php file

<?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';
?>

You forgot to concatenate here

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM