繁体   English   中英

无法使用xampp发布我的php文件

[英]Cannot post my php file, using xampp

我正在尝试在我的网站上设置一个HTML联系人表单,该表单将使用PHP将表单中输入的信息发送到我的电子邮件地址。

不幸的是,我不断收到一条错误消息,提示Cannot POST /form.php并且我不知道为什么。

我查看了在StackExchange上问过的类似问题,第一原因似乎是PHP文件与index.html文件不在同一文件夹中。 但是,我的两个文件都在同一个文件夹中。 newwebsite/index.htmlnewwebsite/form.php

那么,为什么会这样呢?

这是我的index.html表单:

<form method='post' action='form.php'>
                <label>Name: </label>
                <input type='text' name='vistorName' id='form-name' placeholder="Type your name.." required>
                <br>
                <label>Email: </label>
                <input type='email' name='vistorEmail' id='form-email' placeholder="Type your email.." required>
                <br>
                <label>Msg: </label>
                <textarea type='text' name='vistorMsg' id='form-msg' placeholder="Type your message here..." required></textarea>
                <br>
                <input type='submit' action="submit" value='Submit' id='submit-button' required><br>
            </form>

这是我的form.php文件:

<?php
    //Pulling values that were entered into the form.
$name = $_POST['visitorName'];
$email = $_POST['visitorEmail'];
$message = $POST['visitorMsg'];

//Structure of email that I will receive with the form info
$email_from = "myemail@email.com";
$email_subject = 'New Contact Form Message';
$email_body = "You have received a new message from $name. \n".
                "Here is the message: \n $message".

//Sending to my email address and using the mail function
    $to = "zcericola@gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email \r\n";
mail($to,$email_subject,$email_body,$headers);

//Validating the form
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;
    }

}

if(IsInjected($email))
{
    echo "Bad email value!";
    exit;
}





?>

//HTML confirmation that message was sent.
    <html lang='en'>
    <h1>Your email has been sent. Thank-you!</h1>



    </html>

进行一些修改,您的代码即可在我的服务器上运行。

根据Akintunde的评论,您的表单在字段名称中有错别字:

<html>
<form method='post' action='form.php'>
                <label>Name: </label>
                <input type='text' name='visitorName' id='form-name' placeholder="Type your name.." required>
            <br>
            <label>Email: </label>
            <input type='email' name='visitorEmail' id='form-email' placeholder="Type your email.." required>
            <br>
            <label>Msg: </label>
            <textarea type='text' name='visitorMsg' id='form-msg' placeholder="Type your message here..." required></textarea>
            <br>
            <input type='submit' action="submit" value='Submit' id='submit-button' required><br>
        </form>

尝试发送电子邮件后,您的“ form.php”将检查电子邮件地址。 另外,html注释的标识与php注释的标识不同。 我做了这两个更改。

<?php
//Pulling values that were entered into the form.
$name = $_POST['visitorName'];
$email = $_POST['visitorEmail'];
$message = $POST['visitorMsg'];

if(IsInjected($email))
{
echo "Bad email value!";
exit;
}


//Structure of email that I will receive with the form info
$email_from = "myemail@email.com";
$email_subject = 'New Contact Form Message';
$email_body = "You have received a new message from $name. \n".
            "Here is the message: \n $message".

//Sending to my email address and using the mail function
$to = "zcericola@gmail.com";
$headers = "From: $email_from \r\n";
$headers .= "Reply-To: $email \r\n";
mail($to,$email_subject,$email_body,$headers);

//Validating the form
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;
}

}



?>
    <html lang='en'>

<!-- HTML confirmation that message was sent. -->
    <h1>Your email has been sent. Thank-you!</h1>

    </html>

暂无
暂无

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

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