我对PHP的知识有点非常,因此我使用了联系表单生成器,但它无法正常运行。电子邮件确实发送成功,但只检测到“电子邮件”和“选项”弹出窗口。其他任何东西都是空的。
这是代码。
form.php的
<?=$message?>
<form id="FormName" action="send.php" method="post" name="FormName">
<table width="448" border="0" cellspacing="2" cellpadding="0">
<tr><td width = "150" align="right"><label for="EmailFrom">Your E-mail</label></td>
<td><input id="EmailFrom" type="text" name="EmailFrom" size="25"></td></tr>
<tr><td width = "150" align="right" valign="top"><label for="text_field">text field</label></td>
<td valign="top"><input id="text_field" name="text_field" type="text" size="25" value="<?=$text_field?>" maxlength="255"></td></tr><tr><td width = "150" align="right" valign="top"><label for="hello_world_1">Hello world 1</label></td>
<td valign="top"><input id="hello_world_1" name="hello_world_1" type="checkbox" value="Y"></td></tr><tr><td width = "150" align="right" valign="top"><label for="hello_world_2">Hello world 2</label></td>
<td valign="top"><input id="hello_world_2" name="hello_world_2" type="checkbox" value="Y"></td></tr><tr><td width = "150" align="right" valign="top"><label for="hello_world_3">Hello World 3</label></td>
<td valign="top"><input id="hello_world_3" name="hello_world_3" type="checkbox" value="Y"></td></tr><tr><td width = "150" align="right" valign="top"><label for="text_area">text area</label></td>
<td valign="top"><textarea id="text_area" name="text_area" rows="4" cols="40"><?=$text_area?></textarea></td></tr><tr><td width = "150" align="right" valign="top"><label for="popup">popup</label></td>
<td valign="top"><select id="popup" name="popup" size="1">
<option value="Option 1"<?php if($popup == "Option 1"){echo " selected";}?>>Option 1</option>
<option value="Option 2"<?php if($popup == "Option 2"){echo " selected";}?>>Option 2</option>
<option value="Option 3"<?php if($popup == "Option 3"){echo " selected";}?>>Option 3</option>
</select></td></tr><tr><td width = "150" align="right" valign="top"><label for="date">date</label></td>
<td valign="top"><input id="date" name="<?=$date?>" type="text" size="25" value="<?=$date?>" maxlength="255"></td></tr><tr><td width = "150" align="right" valign="top"><label for="hidden">hidden</label></td>
<td valign="top"><input type="hidden" name="hidden" value="<?=$hidden?>"></td></tr><tr><td width = "150" align="right" valign="top"><label for="image">image</label></td>
<td valign="top"><input type="hidden" name="hidden" value="<?=$hidden?>"></td></tr><tr>
<td width="150"></td>
<td>
<input type="submit" name="submitButtonName" value="Send E-mail"></td>
</tr>
</table>
</form>
send.php
<?php
$EmailFrom = $_POST['EmailFrom'];
$text_field = trim($_POST['text_field']);
$hello_world_1 = trim($_POST['hello_world_1']);
$hello_world_2 = trim($_POST['hello_world_2']);
$hello_world_3 = trim($_POST['hello_world_3']);
$text_area = trim($_POST['text_area']);
$popup = trim($_POST['popup']);
$date = trim($_POST['date']);
$hidden = trim($_POST['hidden']);
$image = trim($_POST['image']);
$EmailTo = "nomail@nomail.com";
$Subject = ""; /// Add a subject
$validationOK=true;
if (trim($EmailFrom)=="") $validationOK=false;
if (!$validationOK) {
echo "Error! E-mail was not sent. Please check you code.";
exit;
}
$Body = "";
$Body .= "text field:\n$textfield\n\n";
$Body .= "Hello world 1:\n$helloworld1\n\n";
$Body .= "Hello world 2:\n$helloworld2\n\n";
$Body .= "Hello World 3:\n$helloworld3\n\n";
$Body .= "text area:\n$textarea\n\n";
$Body .= "popup:\n$popup\n\n";
$Body .= "date:\n$date\n\n";
$Body .= "hidden:\n$hidden\n\n";
$Body .= "image:\n$image\n\n";
if($Subject == NULL) {$Subject = "From $EmailFrom";}
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
if ($success){ echo "Success! Your e-mail was sent!";}
else{ echo "Error! Your e-mail was not sent!";}
?>
为什么它不起作用?此外,如果你可以推荐一个工作的PHP表单生成器,这将是非常有帮助的。我需要复选框和弹出/单选按钮。
答案 0 :(得分:1)
您的变量的名称类似于“$ text_field”(带有下划线)但是当附加到$ Body时,您不会使用下划线,例如“$文本框”。因此变量“$ textfield”甚至没有设置,意味着空。