PHP发送到电子邮件时从表单中丢失用户输入

时间:2016-06-08 13:32:04

标签: php html webforms submit

我使用phpform.org创建了一个表单。在Mohamed Athif的帮助下,现在有一个部分工作的mail.php,我现在正在接收电子邮件,但我无法将用户输入到电子邮件中。我明白我必须为.php文件中的每个字段添加元素。如果有人可以提供一些指导,让这些元素与电子邮件一起工作,那么我可以将它们应用到所有其他元素,我这里是html代码。

对于电子邮件中的元素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 = "me@gmail.com";
$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>";
?>

1 个答案:

答案 0 :(得分:3)

在原始代码中,你是 1)调用一个不存在的变量$ element81
2)元素6之前缺少$符号 这就是为什么你没有得到所需的内容。

以下代码会在您的电子邮件中提供以下内容(根据您的要求)

您想使用什么别名 - (用户输入)
这是关于 - (无论用户点击好工作还是坏工作)
什么是工作场所的名称..(用户输入)

替换

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

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