一直在努力只发送人们填写的字段。这是一个带有文本字段的简单订单。但我希望它只有那些在字段中的字段才能发送到我的警报电子邮件。我尝试了主题“PHP 表单:仅填充字段的成功电子邮件”的代码,但是当我这样做时,我的 php 脚本崩溃了。这是我尝试任何修改之前的代码。这封电子邮件很好,只是它包含了我只希望填写的所有字段。请帮助我在 php 中完全是菜鸟。所有帮助表示赞赏。
<?
$silver_name_badges = !empty($_POST['silver_name_badges']) ? ($_POST['silver_name_badges'])) : false;
$silver_name_badges = $_POST['silver_name_badges'];
$coffee_mug = $_POST['coffee_mug'];
$plastic_bag = $_POST['plastic_bag'];
$paper_bag = $_POST['paper_bag'];
$candy = $_POST['candy'];
$moist_towlette = $_POST['moist_towlette'];
$notepad_and_pen = $_POST['notepad_and_pen'];
$tuck_box = $_POST['tuck_box'];
$red_tie = $_POST['red_tie'];
$cap = $_POST['cap'];
$name = $_POST['Attention_To'];
$red_lanyard = $_POST['red_lanyard'];
$white_lanyard = $_POST['white_lanyard'];
$green_lanyard = $_POST['green_lanyard'];
$black_lanyard = $_POST['black_lanyard'];
$LC2415 = $_POST['LC2415'];
$FOM_2NTRI = $_POST['FOM_2NTRI'];
$ASTRO_165WMT = $_POST['ASTRO_165WMT'];
$FOL_AJ3015 = $_POST['FOL_AJ3015'];
$ACIES_NT = $_POST['ACIES_NT'];
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.ama-japan.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', 'ravila@ama.com');
// Set parameters of the email
$to = "joe@ama.com";
$subject = "Ama Promo Items Ordered";
$from = " jurt@ama.com";
$headers = "From: $from";
$message = "";
$message .= "Order has been placed. Attn to: $name .\n
Items:\n";
if($Phone)
$Body .= "Phone: "; $Body .= $Phone; $Body .= "\n";
$message .="
Silver Name Badges: $silver_name_badges\n
Coffee Mug: $coffee_mug\n
Plastic Literature Bag: $plastic_bag\n
Amada Bag: $paper_bag\n
Candy: $candy\n
Notepad & Pen: $notepad_and_pen\n
Tuck Box: $tuck_box\n
Amada Tie: $red_tie\n
Candy: $candy\n
Moist Towlette: $moist_towlette\n
Cap: $cap\n
Lanyard:
Red - $red_lanyard
White - $white_lanyard
Green - $green_lanyard
Black - $black_lanyard\n
Rock Glass:
LC2415 - $LC2415
FOM 2NTRI - $FOM_2NTRI
ASTRO 165WMT - $ASTRO_165WMT
FOL AJ3015 - $FOL_AJ3015
ACIES NT - $ACIES_NT";
// Mail function that sends the email.
mail($to,$subject,$message,$headers);
header('Location: thank-you.html');
?>