0

我的 php 邮件表单在我的邮箱中是空的,由于某种原因它没有收集在 HTML 中输入的文本字段信息。

这是它在我的邮箱中的显示方式:

Email: 
First Name: 
Last Name: 
Phone: 
Vehicle:
Engine: 
Tickbox Engine: 
Tickbox Aerodynamics: 
Tickbox Wheels: 
Tickbox Suspension: 
Tickbox Exhaust: 
Tickbox Brakes: 
Tickbox Interior: 
Message:

这是我的 php 代码:

    $firtnameField = $_POST['firstname'];
    $lastnameField = $_POST['lastname'];
    $phonenameField = $_POST['phone'];
    $emailField = $_POST['email'];  
    $vehicleField = $_POST['vehicle'];  
    $engineField = $_POST['engine'];
    $tickboxengineField = $_POST['infoengine']; 
    $tickboxaerodynamicsField = $_POST['infoaero']; 
    $tickboxwheelsField = $_POST['infowheels']; 
    $tickboxsuspensionField = $_POST['infosuspension']; 
    $tickboexhaustField = $_POST['infoexhaust'];    
    $tickboxbrakesField = $_POST['infobrakes']; 
    $tickboxinteriorField = $_POST['infointerior']; 
    $tickboxmessageField = $_POST['message'];   
    $tickboxsendField = $_POST['infosend']; 

    $body = <<<EOD
<br><hr><br>
Email: $email <br>
First Name: $firstname <br>
Last Name: $lastname <br>
Phone: $phone <br>
Vehicle: $vehicle <br>
Engine: $engine <br>
Tickbox Engine: $infoengine <br>
Tickbox Aerodynamics: $infoaero <br>
Tickbox Wheels: $infowheels <br>
Tickbox Suspension: $infosuspension <br>
Tickbox Exhaust: $infoexhaust <br>
Tickbox Brakes: $infobrakes <br>
Tickbox Interior: $infointerior <br>
Message: $message <br>
EOD;

    $headers = "From: $email\r\n";
    $headers .= "Content-type: text/html\r\n";
    $succes = mail($webMaster, $emailSubject, $body, $headers);

这是我的 HTML:

    <form id="form1" name="form1" method="post" action="requestform.php">
      <table width="540" border="0" align="center" cellpadding="0" cellspacing="0">
        <tr valign="bottom">
          <td width="48%" height="30" class="subheadline">First Name</td>
          <td width="4%" height="30">&nbsp;</td>
          <td width="48%" height="30" class="subheadline">Last Name</td>
        </tr>
        <tr>
          <td width="48%"><input name="firstname" type="text" id="firstname" size="45" /></td>
          <td width="4%">&nbsp;</td>
          <td width="48%"><input name="lastname" type="text" id="lastname" size="45" /></td>
        </tr>
        <tr valign="bottom">
          <td width="48%" height="30" class="subheadline">Phone</td>
          <td width="4%" height="30">&nbsp;</td>
          <td width="48%" height="30" class="subheadline">Email</td>
        </tr>
        <tr>
          <td width="48%"><input name="phone" type="text" id="phone" size="45" /></td>
          <td width="4%">&nbsp;</td>
          <td width="48%"><input name="email" type="text" id="email" size="45" /></td>
        </tr>
        <tr valign="bottom">
          <td width="48%" height="30" class="subheadline">Vehicle &amp; Model</td>
          <td width="4%" height="30">&nbsp;</td>
          <td width="48%" height="30" class="subheadline">Engine</td>
        </tr>
        <tr>
          <td width="48%"><input name="vehicle" type="text" id="vehicle" size="45" /></td>
          <td width="4%">&nbsp;</td>
          <td width="48%"><input name="engine" type="text" id="engine" size="45" /></td>
        </tr>
        <tr valign="bottom">
          <td width="48%" height="30" class="subheadline">Please select</td>
          <td width="4%" height="30">&nbsp;</td>
          <td width="48%" height="30">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="3"><table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
              <td height="25"><input type="checkbox" name="infoengine" id="infoengine" />
Engine Technology</td>
              <td height="25"><input type="checkbox" name="infoaero" id="infoaero" />
                Aerodynamics</td>
              <td height="25"><input type="checkbox" name="infowheels" id="infowheels" />
Sport Wheels</td>
              <td height="25"><input type="checkbox" name="infosuspension" id="infosuspension" />
                Suspension</td>
              </tr>
            <tr>
              <td height="25"><input type="checkbox" name="infoexhaust" id="infoexhaust" />
Exhaust Technology</td>
              <td height="25"><input type="checkbox" name="infobrakes" id="infobrakes" />Brake Technology</td>
              <td height="25"><input type="checkbox" name="infointerior" id="infointerior" />
                Interior</td>
              <td height="25">&nbsp;</td>
              </tr>
          </table></td>
          </tr>
        <tr valign="bottom">
          <td width="48%" height="30" class="subheadline">Message</td>
          <td width="4%" height="30">&nbsp;</td>
          <td width="48%" height="30">&nbsp;</td>
        </tr>
        <tr>
          <td colspan="3"><textarea name="message" id="message" cols="74" rows="5">Please send me information…&lt;/textarea></td>
          </tr>
        <tr valign="bottom">
          <td width="48%" height="30">&nbsp;</td>
          <td width="4%" height="30" align="right">&nbsp;</td>
          <td width="48%" height="30" align="right"><input type="submit" name="send" id="send" value="Request Information" /></td>
        </tr>
      </table>
    </form>

我相信您可以看到我离成为专业人士还很遥远,这是我正在尝试的第一个 PHP 邮件表单。观看了教程并尝试将其转换为我的需求……感谢任何输入。

4

3 回答 3

3

您丢失了Field用于打印的每个第二个变量名称的后缀。例如,$firtnameField它就变成了$firstname

于 2013-06-09T13:07:15.853 回答
1

您缺少原始名称$body

$firtnameField = $_POST['firstname'];
....

您忘记Field了变量中的后缀

$body = <<<EOD
<br><hr><br>
Email: $emailField <br>
First Name: $firstnameField <br>
Last Name: $lastnameField <br>
Phone: $phoneField <br>
....
于 2013-06-09T13:07:49.567 回答
-1

兄弟使用这个
可以工作的php代码将它添加到php页面上

$webmaster = 'yoour_email@mail.com';
$emailSubject = 'Your Subjject here';

    $firtnameField = $_POST['firstname'];
    $lastnameField = $_POST['lastname'];
    $phonenameField = $_POST['phone'];
    $emailField = $_POST['email'];  
    $vehicleField = $_POST['vehicle'];  
    $engineField = $_POST['engine'];
    $tickboxengineField = $_POST['infoengine']; 
    $tickboxaerodynamicsField = $_POST['infoaero']; 
    $tickboxwheelsField = $_POST['infowheels']; 
    $tickboxsuspensionField = $_POST['infosuspension']; 
    $tickboexhaustField = $_POST['infoexhaust'];    
    $tickboxbrakesField = $_POST['infobrakes']; 
    $tickboxinteriorField = $_POST['infointerior']; 
    $tickboxmessageField = $_POST['message'];   
    $tickboxsendField = $_POST['infosend']; 

    $body = <<<EOD
<br><hr><br>
Email: $emailField <br>
First Name: $firtnameField <br>
Last Name: $lastnameField <br>
Phone: $phonenameField <br>
Vehicle: $vehicleField <br>
Engine: $engineField <br>
Tickbox Engine: $tickboxengineField <br>
Tickbox Aerodynamics: $tickboxaerodynamicsField <br>
Tickbox Wheels: $tickboxwheelsField <br>
Tickbox Suspension: $tickboxsuspensionField <br>
Tickbox Exhaust: $tickboexhaustField <br>
Tickbox Brakes: $infobrakes <br>
Tickbox Interior: $tickboxinteriorField <br>
Message: $tickboxmessageField <br>
EOD;

    $headers = "From: Alpha RooT <$email>\r\n";
    $headers .= "Content-type: text/html\r\n";
    $succes = mail($webMaster, $emailSubject, $body, $headers);
于 2013-06-09T13:27:34.307 回答