简体   繁体   English

使用php将表单发送到我的电子邮件。提交表单时出现405不允许的问题

[英]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. 从我创建的表单获取数据并将其通过php传递到我的电子邮件时遇到问题。 Here's the link with the form http://kapena.github.io/pp_web/#contact-pp 这是格式为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 我目前在gh页上托管此版本

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. 我对此进行了一些研究,发现了错误405的补丁,但我不知道如何在我的项目中实现此解决方案。 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 我只是一个初学者,需要一些指导。这是我找到的解决方法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. 这是我的php代码,因此您可以检查该代码以查看是否存在并发出导致该问题的多数民众赞成。

Any help would be greatly appreciated here..Trying to launch b4 the new year :) 任何帮助将不胜感激..尝试在新的一年推出b4 :)

<?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? 我的HTML ..我觉得它与method='post'可能是问题所在吗?

<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 看起来http://php.net/manual/en/function.mail.php

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

$mail is not variable is function then $ mail不是变量就是函数

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. 我修改了您的代码,发现很多错误。正确的代码如下:-在您的代码上发现以下错误1.使用if(isset($ _ POST [“ submit”])){代替if($ _ POST [“ submit”]] } {2.您为textarea使用了错误的变量名。 you should use $message = $_POST["yourMessage"]; 您应该使用$ message = $ _POST [“ yourMessage”]; instead of $message = $_POST["message-me"]; 而不是$ 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. 4.另一个错误是您的表单操作位于Submit_form.php页面,但我发现您的邮件代码位于页面顶部。 if you want to submit to another page then use php code to submit_form.php page. 如果您想提交到另一个页面,则使用php代码来Submit_form.php页面。 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 5.代码的主要和重要错误我发现您在发送邮件的地方使用了Gmail电子邮件。但是如果您使用其他域电子邮件,则应使用brentw.white@kapena.github.io之类的域电子邮件由于可疑,您的邮件进入了垃圾邮件,我认为这对您有帮助,我在这里使用了您的链接: -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: 我之所以这么想是因为您在github服务器上开发,并且他不允许POST更改您的代码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. 和PHP将$ _POST更改为$ _GET,但是长度有问题,因为所有数据都在URL中发送。

If you want public page to normal server return back to POST method 如果要将公共页面发送到普通服务器,请返回POST方法

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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