只是在发送人们填写的字段时苦苦挣扎。这是一个带文本字段的简单订单。但我希望它只有那些字段中的字段才能发送到我的警报电子邮件中。我在主题"PHP form: Success email with only filled fields"上尝试了代码,但是当我这样做时,我的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');
?>
答案 0 :(得分:0)
错误可能与未设置的POST变量有关。
循环怎么样?它只会使用发送的内容。
$message = "";
$message .= "Order has been placed. Attn to: $name .\n
Items:\n";
foreach ($_POST as $fieldName => $fieldValue){
if (!empty($fieldValue))
$message .= " ". str_replace('_',' ',$fieldName) .": $fieldValue\n";
}
答案 1 :(得分:0)
好的,我添加了这个,效果很好。电子邮件如何返回带有下划线的字段名称。如何发送没有下划线?:
<?php
//$silver_name_badges = !empty($_POST['silver_name_badges']) ? ($_POST['silver_name_badges'])) : false;
$SilverNameBadges = $_POST['Silver Name Badges'];
$CoffeeMug = $_POST['coffee_mug'];
$PlasticLiteratureBag = $_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.amada-america.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@amada.com');
// Set parameters of the email
$to = "ravila@amada.com";
$subject = "Amada Promo Items Ordered";
$from = " nostrowski@amada.com";
$headers = "From: $from";
$message = "";
$message .= "Order has been placed. Attn to: $name .\n
Items:\n";
foreach ($_POST as $fieldName => $fieldValue){
if (!empty($fieldValue))
$message .= " $fieldName: $fieldValue\n";
}
// Mail function that sends the email.
mail($to,$subject,$message,$headers);
header('Location: thank-you.html');
?>