仅发送人们填写的字段就非常麻烦。这是一个简单的带有文本字段的订单。 但我希望这样做,以便仅将字段中的那些字段发送到我的警报电子邮件中。 我尝试了“ 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');
?>

===============>>#1 票数: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";
}

===============>>#2 票数: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');
?>

  ask by NewHistoricForm translate from so

未解决问题?本站智能推荐:

关注微信公众号