0

I've taken the first part of this tutorial: http://www.1stwebdesigner.com/tutorials/custom-php-contact-forms/ and edited to suit my needs but when I click Submit on the form it takes me to the php page.

When I click submit I want it to submit the form and the result of the form be emailed to me. I dont know PHP (hence why I was looking at a tutorial), so it is probably a really silly mistake :/

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

My 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!";
?>

Any help is appreciated.

4

1 回答 1

0

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

    <?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 即可在表单页面上使用它。

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

于 2013-10-01T06:28:46.600 回答