0

我对 PHP 的了解非常有限,所以我使用了联系表单生成器,但它无法正常工作。电子邮件确实发送成功,但仅检测到“电子邮件”和“选项”弹出窗口。其他任何东西都返回空。

这是代码。

表单.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>

发送.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 表单生成器,那将非常有帮助。我需要复选框和弹出/单选按钮。

4

1 回答 1

1

您的变量被命名为“$text_field”(带下划线),但是当附加到 $Body 时,您不使用下划线,例如“$textfield”。因此,甚至没有设置变量“$textfield”,即为空。

于 2012-07-17T14:05:53.983 回答