简体   繁体   中英

Using php to send form to my email..Having an issue with 405 Not Allowed when form is submitted

Having an issue with getting data from a form that I created and passing it into my email through php. Here's the link with the form http://kapena.github.io/pp_web/#contact-pp

Here's the exact issue.. When I click submit on the form button I get this error message saying.. 错误信息

I'm currently hosting this build on a gh-pages

I did some research on this and I found a patch for the error 405 but I have no idea how to implement this solution into my project. I am just a beginner and I need some instruction..Here's the solution I found https://gist.github.com/baskaran-md/e46cc25ccfac83f153bb#file-nginx-conf

How can I implement this solution correctly into my site?
Here's my php code so you can inspect that to see if there's and issue there thats causing this problem.

Any help would be greatly appreciated here..Trying to launch b4 the new year :)

<?php
if($_POST["submit"]) {
$recipient = "brentw.white@gmail.com"; //my email
$subject = 'Email message from Point Plumbing';
$name = $_POST ["yourName"];
$email = $_POST["yourEmail"];
$phone = $_POST["yourPhone"];
$location = $_POST["yourLocate"];
$message = $_POST["message-me"];

$mailBody="Name: $name\nEmail: $email\n\n$message";
$mail($recipient, $subject, $mailBody, "From: $name <$email>");
$thankYou="<p>Thank you! We will be in contact with you shortly.</p>";
}
?>

My HTML..I have a feeling it has something to do with method='post' possible that's the issue?

<form action="submit_form.php" method="post" id="spaceing" data-abide>
        <div class="form-bg">
            <div class="row">
                <div id="name" class="large-6 medium-6 small-12 columns">
                    <label> <h5>Name</h5>
                        <input type="text" name="yourName" placeholder="What is you're name?"></input>
                    </label>
                </div>

                <div id="email" class="large-6 medium-6 small-12 columns">
                    <label><h5>Email</h5>
                        <input type="email" name="yourEmail" placeholder="Please enter in you're email."required></input>
                    </label>
                    <small class="error">An email Address is required.</small>
                </div>
            </div>

                <div class="row">
                    <div id="phone"class="large-6 medium-6 small-12 columns">
                        <label><h5>Phone</h5>
                            <input type="text" name="yourPhone" placeholder="Please enter you're phone number."></input>
                        </label>
                    </div>

                    <div id="location" class="large-6 medium-6 small-12 columns">
                        <label><h5>Location</h5>
                            <input type="text" name="yourLocate" placeholder="Where on Oahu are you currently living?"></input>
                        </label>
                    </div>
                </div>

                <div class="row">
                    <div id="message-area" class="large-12 medium-12 small-12 columns">
                        <label><h5>Message</h5>
                            <textarea id="message" name="yourMessage" placeholder="Please tell us about you're plumbing issues."></textarea>
                        </label>
                    </div>
                </div>

            <div class="row">
                <div id="submit" class="large-3 medium-3 small-3 columns">
                    <button type="submit-me">Submit</button>
                </div>
            </div>
        </div>
    </form>

look http://php.net/manual/en/function.mail.php

$mail($recipient, $subject, $mailBody, "From: $name <$email>");

$mail is not variable is function then

mail($recipient, $subject, $mailBody, "From: $name <$email>");

I modified your code and find lots of error.correct code is below:- found following error on your code 1. use if(isset($_POST["submit"])) { instead of if($_POST["submit"]) { 2. you use wrong variable name for textarea. you should use $message = $_POST["yourMessage"]; instead of $message = $_POST["message-me"]; 4. another error is your form action is at submit_form.php page but i found your mail code is at top of your page. if you want to submit to another page then use php code to submit_form.php page. 5. Main and important error of your code i found you using your gmail email at the place of sending mail.but you should use your domain email like brentw.white@kapena.github.io if you using another domain email these mail are count as suspicious and your mail goes to spam I think it will be help full for you I used your link here:- http://smartzonewebservices.com/mtg/del.php

<?php
if(isset($_POST["submit"])) {
$recipient = "brentw.white@gmail.com"; //my email
echo $subject = 'Email message from Point Plumbing';
echo $name = $_POST ["yourName"];
echo $email = $_POST["yourEmail"];
echo $phone = $_POST["yourPhone"];
echo $location = $_POST["yourLocate"];
echo  $message = $_POST["yourMessage"];

 $mailBody="Name: $name\nEmail: $email\n\n$message"; 

 mail($recipient, $subject, $mailBody, "From: $name <$email>");

echo $thankYou="<p>Thank you! We will be in contact with you shortly.</p>";

}
?>
<form action="" method="post" id="spaceing" data-abide>
        <div class="form-bg">
            <div class="row">
                <div id="name" class="large-6 medium-6 small-12 columns">
                    <label> <h5>Name</h5>
                        <input type="text" name="yourName" placeholder="What is you're name?"></input>
                    </label>
                </div>

                <div id="email" class="large-6 medium-6 small-12 columns">
                    <label><h5>Email</h5>
                        <input type="email" name="yourEmail" placeholder="Please enter in you're email."required></input>
                    </label>
                    <small class="error">An email Address is required.</small>
                </div>
            </div>

                <div class="row">
                    <div id="phone"class="large-6 medium-6 small-12 columns">
                        <label><h5>Phone</h5>
                            <input type="text" name="yourPhone" placeholder="Please enter you're phone number."></input>
                        </label>
                    </div>

                    <div id="location" class="large-6 medium-6 small-12 columns">
                        <label><h5>Location</h5>
                            <input type="text" name="yourLocate" placeholder="Where on Oahu are you currently living?"></input>
                        </label>
                    </div>
                </div>

                <div class="row">
                    <div id="message-area" class="large-12 medium-12 small-12 columns">
                        <label><h5>Message</h5>
                            <textarea id="message" name="yourMessage" placeholder="Please tell us about you're plumbing issues."></textarea>
                        </label>
                    </div>
                </div>

            <div class="row">
                <div id="submit" class="large-3 medium-3 small-3 columns">
                    <button name="submit" type="submit">Submit</button>
                </div>
            </div>
        </div>
    </form>

I thing this going because you develop on github server and he does not allow make POST change your code HTML:

<form action="submit_form.php" method="get" id="spaceing" data-abide>

and PHP change $_POST for $_GET but there is problem with length because all data is sending in URL.

If you want public page to normal server return back to POST method

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