实际上,您想要的 PHP 邮件表单并不容易,但我一直在努力提供帮助,即使您没有绘制您想要的表单,也没有绘制主题。现在,例如我们有一个名为form.php的 PHP 文件,这是 PHP 脚本:
<?php
$q = addslashes($_GET["q"]);
if (empty($q)) {
echo '<form action="form.php" method="get">
How many do you want to order: <input type="text" name="q">
<input type="submit">
</form>';
}
if ($q > 0) {
if (isset($_REQUEST['from'])) {
$from = $_REQUEST['from'] ;
// place your email here
$to = "mail@example.com";
$subject = "Customer: " . $_REQUEST['name'];
$i = 1;
while ($i <= $q) {
$message .= "Order $i\n";
$message .= "Quality: " . $_REQUEST['quality' . $i] . "\n";
$message .= "Color: " . $_REQUEST['color' . $i] . "\n";
$message .= "Description: " . $_REQUEST['description' . $i] . "\n\n";
$i++;
}
$message .= "Note: " . $_REQUEST['note'];
mail($to, $subject, $message, "From:" . $from);
echo "Thank you for submitting your order!";
} else {
echo "<form method='post'>
Email: <input name='from' type='text'><br />
Full Name: <input name='name' type='text'><br />";
$i = 1;
while ($i <= $q) {
echo "Order $i<br />
Quality: <input name='quality" . $i . "' type='text'><br />
Color: <input name='color" . $i . "' type='text'><br />
Description: <input name='description" . $i . "' type='text'><br />";
$i++;
}
echo "Additional Note:<br />
<textarea name='note' rows='15' cols='40'></textarea><br />
<input type='submit'>
</form>";
}
}
?>
该邮件表单已经过测试并且可以正常工作。只需完成其余的改进和样式设置即可。