2013-10-01 33 views
0

我已經採取了本教程的第一部分:http://www.1stwebdesigner.com/tutorials/custom-php-contact-forms/並進行了編輯以適合我的需求,但是當我單擊表單上的提交時,它會將我帶到php頁面。點擊Sumbit帶我到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 protected]"; 
$subject = "Kando Application!"; 
$mailheader = "From: $email \r\n"; 
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); 
echo "Thank You!"; 
?> 

任何幫助表示讚賞。

+0

那麼你的問題是什麼? –

+0

當你把它帶到PHP頁面時,它顯示了什麼?編譯器錯誤或「錯誤!」或「謝謝你!」? – George

+0

@George它顯示PHP代碼。 – roryjt

回答

0

在這種情況下,您需要使用谷歌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使用它你的窗體頁上。

如果您遇到問題,請給我一個測試文件的鏈接,我將指導您如何使用它。