2016-06-08 22 views
0

我使用phpform.org創建了一個表單並且在Mohamed Athif的一些幫助下,現在有一個部分工作的mail.php,我現在正在接收電子郵件,但我無法獲得用戶輸入進入電子郵件。我明白我必須爲.php文件中的每個字段添加元素。如果有人可以提供一些指導,讓這些元素處理電子郵件,所以我可以將它們應用到所有其他元素,我自己這裏是html代碼。PHP在發送到電子郵件時從表單中缺少用戶輸入

對於元素1,8,6的電子郵件,我希望它是如下或類似於此

What alias do you want to use - (User Input) 
    Is this about - (whatever the user clicked either good Job or bad Job) 
    What is the name of the workplace.. (user Input) 

目前在電子郵件即時得到這個

From: alias 
Message: Is this about a , Where is this Business Located? element6, 

所以你可以看到用戶輸入丟失。

<form method="post" action="mail.php"> 
       <div class="form_description"> 
     <h2>GoodJob - BadJob</h2> 
     <p>some text here</p> 
    </div>      
     <ul > 

       <li id="li_1" > 
    <label class="description" for="element_1">What is the Alias you want to use </label> 
    <div> 
     <input id="element_1" name="element_1" class="element text medium" type="text" maxlength="255" value=""/> 
    </div><p class="guidelines" id="guide_1"><small>You don't have to use your real name - Just remember your Alias for Comments</small></p> 
    </li>  <li id="li_8" > 
    <label class="description" for="element_8">Is this about a ...... </label> 
    <span> 
     <input id="element_8_1" name="element_8" class="element radio" type="radio" value="1" /> 
<label class="choice" for="element_8_1">Bad job</label> 
<input id="element_8_2" name="element_8" class="element radio" type="radio" value="2" /> 
<label class="choice" for="element_8_2">Good Job</label> 

    </span> 
    </li>  <li id="li_6" > 
    <label class="description" for="element_6">What is the name of the workplace you want to tell us about? </label> 
    <div> 
     <input id="element_6" name="element_6" class="element text medium" type="text" maxlength="255" value=""/> 
    </div><p class="guidelines" id="guide_6"><small>Type in the Name of the Business</small></p> 
    </li>  <li id="li_16" > 
    <label class="description" for="element_16">Where is this Business Located? </label> 
    <div> 
     <input id="element_16" name="element_16" class="element text medium" type="text" maxlength="255" value=""/> 
    </div><p class="guidelines" id="guide_16"><small>Type in the town, or you can find the business on google maps and click on share and copy the link and paste it here.</small></p> 
    </li>  <li id="li_7" > 
    <label class="description" for="element_7">If you want to mention the bosses name, Put it here. </label> 
    <div> 
     <input id="element_7" name="element_7" class="element text medium" type="text" maxlength="255" value=""/> 
    </div><p class="guidelines" id="guide_7"><small>Type in the Name of the Boss</small></p> 
    </li>  <li id="li_15" > 
    <label class="description" for="element_15">If you know the personal page you can copy and paste it in here </label> 
    <div> 
     <input id="element_15" name="element_15" class="element text large" type="text" maxlength="255" value=""/> 
    </div><p class="guidelines" id="guide_15"><small>Go to the top address bar of the boss/owner you want to tag for this post. Select all the text and paste it in the box.</small></p> 
    </li>  <li id="li_9" > 
    <label class="description" for="element_9">How many hours a week do you work? </label> 
    <span> 
     <input id="element_9_1" name="element_9" class="element radio" type="radio" value="1" /> 

1至10 10至20 20至30 30至40 40至50 50個小時加上

</span><p class="guidelines" id="guide_9"><small>Keep it REAL. </small></p> 
    </li>  <li id="li_18" > 
    <label class="description" for="element_18">Exactly how many hours do you work? </label> 
    <div> 
     <input id="element_18" name="element_18" class="element text medium" type="text" maxlength="255" value=""/> 
    </div> 
    </li>  <li id="li_11" > 
    <label class="description" for="element_11">Does your Job Pay Extra Hours? </label> 
    <span> 
     <input id="element_11_1" name="element_11" class="element radio" type="radio" value="1" /> 

是 否

</span> 
    </li>  <li id="li_10" > 
    <label class="description" for="element_10">What type of contract do you have? </label> 
    <span> 
     <input id="element_10_1" name="element_10" class="element radio" type="radio" value="1" /> 

兼職 全職 每週每小時 不知道

</span><p class="guidelines" id="guide_10"><small>DON'T GUESS..This is crucial. Every worker MUST have a copy of their contract. If you don't have one ask your boss or go to the Employment office with ALL your credentials and they will tell you there what contract you have.</small></p> 
    </li>  <li id="li_12" > 
    <label class="description" for="element_12">Did you get Holiday pay? </label> 
    <span> 
     <input id="element_12_1" name="element_12" class="element radio" type="radio" value="1" /> 

是 沒有

</span> 
    </li>  <li id="li_17" > 
    <label class="description" for="element_17">How much holiday pay did you get? </label> 
    <div> 
     <input id="element_17" name="element_17" class="element text medium" type="text" maxlength="255" value=""/> 
    </div><p class="guidelines" id="guide_17"><small>A NUMBER ONLY no symbols or text</small></p> 
    </li>  <li id="li_13" > 
    <label class="description" for="element_13">Did you know That </label> 
    <span> 
     <input id="element_13_1" name="element_13" class="element radio" type="radio" value="1" /> 

是 沒有

</span><p class="guidelines" id="guide_13"><small>Its true, In Spain ins a 14 month pay scheme, where you get a double pay in summer and another Christmas. Most employers will actually incorporate these two payments within your monthly wage</small></p> 
    </li>  <li id="li_14" > 
    <label class="description" for="element_14">Got a story to tell about this Job? Bad or good - let it rip here!</label> 
    <div> 
     <textarea id="element_14" name="element_14" class="element textarea large"></textarea> 
    </div> 
    </li> 

       <li class="buttons"> 
      <input type="hidden" name="form_id" value="1136056" /> 

      <input id="saveForm" class="button_text" type="submit" name="submit" value="Submit" /> 
    </li> 
     </ul> 
    </form> 

和PHP是如下

<?php 
$element1 = $_POST['element_1']; 
$element8 = $_POST['element_8']; 
$element6 = $_POST['element_6']; 

$formcontent="From: $element1 \n Message: Is this about a $element81, Where is this Business Located? element6, blah blah blah"; 
$recipient = "[email protected]"; 
$subject = "Contact Form"; 
$mailheader = "From: $element1 \r\n"; 
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); 
echo "<script type='text/javascript'>alert('Mail sent successfully!')</script>"; 
?> 
+0

取代

$formcontent="From: $element1 \n Message: Is this about a $element81, Where is this Business Located? element6, blah blah blah"; 

請後僅相關的代碼,在這種情況下只有HTML表單元件和PHP部分。解釋你期望的結果並描述錯誤。 –

+0

更改了代碼,並給了我希望得到的東西,我實際上正在接收電子郵件。 –

+0

我看到你得到了答案。快樂編碼:) –

回答

3

在你的原代碼,你
1)被稱爲不存在的變量$ element81
2)有一個$符號元素6
前失蹤這就是爲什麼你沒有得到所需的內容。

下面的代碼會給你在你的電子郵件中提供以下內容(根據您的要求)

什麼別名你想用 - (用戶輸入)
這是有關 - (無論用戶點擊任一好工作或壞工作)
工作單位的名稱是什麼..(用戶輸入)

$formcontent="What alias do you want to use - $element1\n"; 
$formcontent.="Is this about - $element8\n"; 
$formcontent.="Where is this Business Located? - $element6\n"; 
+0

這很好,我現在可以將其應用於其他領域,只有在$元素8的價值被設置爲值=「1」或值=「2」,並在郵件上我得到的價值數字。我已將它改爲value =「bad」和value =「good」,它似乎有效。這種變化會產生任何問題 –

+0

這很好,value =「」的引號內部是傳遞給你的PHP腳本的內容。如果確實需要更改name屬性(即element8),則需要在HTML和PHP腳本上執行此操作。 – SML

+0

@ user6439245在您的第一天36代表...您知道我加入時需要多長時間才能獲得36位代表? *當然,那時我不知道我的.asp是從地下的一個洞裏...... *幹得好,繼續保持下去。 +1。 – gibberish

相關問題