点击提交将我带到php页面

时间:2013-10-01 02:36:43

标签: php html forms email submit

我已经学习了本教程的第一部分:http://www.1stwebdesigner.com/tutorials/custom-php-contact-forms/并根据我的需要进行了编辑,但是当我在表单上单击“提交”时,它会将我带到php页面。

当我点击提交时,我希望它提交表格,表格的结果将通过电子邮件发送给我。我不懂PHP(因此我在看教程的原因),所以这可能是一个非常愚蠢的错误:/

我的HTML:

<form action="mail.php" method="POST">

            <fieldset>

                <h3>Apply</h3>
                    <div class="alert alert-info">
                        <p><strong>Recruitment Status:</strong> Open!</p>
                    </div>
                <hr>
                    <div>
                    <label>Minecraft Username</label>
                    <input type="text" placeholder="Very important!" name="username">
                    <label>Which are you best at?</label>
                    <select name="BestAt">
                        <option>Mining</option>
                        <option>Hunting</option>
                        <option>Farming</option>
                        <option>PvP</option>
                        <option>Raiding</option>
                        <option>Building</option>
                        <option>Redstone</option>
                        <option>Other</option>
                    </select>
                    <label>How many hours are you online each day?</label>
                    <select name="TimeOnline">
                        <option>Less than 2 hrs</option>
                        <option>2-4 hrs</option>
                        <option>4-6 hrs</option>
                        <option>6-8 hrs</option>
                        <option>8-10 hrs</option>
                        <option>More than 10 hrs</option>
                    </select>
                    <label>What rank are you?</label>
                    <select name="rank">
                        <option>Default</option>
                        <option>Member</option>
                        <option>Tier 1</option>
                        <option>Tier 2</option>
                        <option>Tier 3</option>
                        <option>Tier 4</option>
                        <option>Tier 5</option>
                        <option>Moderator</option>
                        <option>Admin/Owner</option>
                    </select>
                    <label>What country do you live in?</label>
                    <input type="text" placeholder="Which Country?" name="country">
                    <label>How old are you?</label>
                    <input type="text" placeholder="Optional" name="age">
                    <label>Previous factions and why you left?</label>
                    <textarea rows="10" placeholder="One faction per line" name="PreviousFactions"></textarea>
                    <label>Why do you want to join Kando?</label>
                    <textarea rows="4" placeholder="Should be atleast 2 sentences" name="WhyYouWantToJoin"></textarea>
                    <hr>
                    <p>You may provide us with your forum username rather than email address or vice versa. It is required that you enter atleast one of them.</p>
                    <label>Email Address (So we can tell you if you've been accepted)</label>
                    <input type="email" placeholder="Please fill in" name="email">
                    <label>Forum Username (So we can add you to our private forum)</label>
                    <input type="text" placeholder="one of these" name="ForumUsername">
                    <hr>
                    <label class="checkbox">
                    <input type="checkbox" value="" name="AgreeToRules">Do you agree to follow our rules?</label>   
                    <hr>
                    <button class="btn btn-large btn-block btn-primary" type="submit" name="submit" value="Send">Submit Application</button>
                    </div>
            </fieldset>

        </form>

我的PHP:

<?php $username = $_POST['username'];
$BestAt = $_POST['BestAt'];
$TimeOnline = $_POST['TimeOnline'];
$rank = $_POST['rank'];
$country = $_POST['country'];
$age = $_POST['age'];
$PreviousFactions = $_POST['PreviousFactions'];
$WhyYouWantToJoin = $_POST['WhyYouWantToJoin'];
$email = $_POST['email'];
$ForumUsername = $_POST['ForumUsername'];
$formcontent=" From: $username \n Best At: $BestAt \n Time Online Daily: $TimeOnline \n Rank: $rank \n Country: $country \n Age: $age \n Previous Factions: $PreviousFactions \n Why $username wants to join: $WhyYouWantToJoin \n Email: $email \n Forum Username: $ForumUsername";
$recipient = "email@address.com";
$subject = "Kando Application!";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";
?>

感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

在这种情况下,您需要使用Google API密钥在有人提交表单时通过您的页面发送电子邮件。尝试使用以下php以上哦你的页面:

    <?php
define('EMAIL_FOR_REPORTS', 'Your Email address here');
define('RECAPTCHA_PRIVATE_KEY', 'Your website private key');
define('FINISH_URI', 'Your web page after submit a form');
define('FINISH_ACTION', 'redirect');
define('FINISH_MESSAGE', 'Your message to show for confirmation');
require_once('Your handler php file here');
?>

正如您在上面的示例中所看到的,只需要添加handler.php即可在表单页面上使用它。

如果您遇到问题,请给我一个测试文件的链接,我会指导您如何使用它。