我有一个脚本,我写的几乎是电子邮件形成数据并将其发送到txt文件。我的问题是如何排除某些消息被发送到文本文件?我不想将此行发送到文本文件:
$message .= "A quote will be forwarded to
Joe Greeninger before order is placed.\n";
请帮忙!怎么样?
<?php
//$silver_name_badges = !empty($_POST['silver_name_badges']) ? ($_POST['silver_name_badges'])) : false;
$SilverNameBadges = $_POST['Silver_Name_Badges'];
$CoffeeMug = $_POST['Coffee_Mug'];
$Plastic_Literature_Bag = $_POST['Plastic_Literature_Bag'];
$Amada_Bag = $_POST['Amada_bag'];
$Candy = $_POST['Candy'];
$Moist_Towlette = $_POST['Moist_Towlette'];
$Notepad_and_Pen = $_POST['Notepad_and_Pen'];
$Tuck_Box = $_POST['Tuck_Box'];
$Amada_Tie = $_POST['Amada_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'];
$Glass_LC2415_NT = $_POST['Glass_LC2415_NT'];
$Glass_FOM2NTRI = $_POST['Glass_FOM2NTRI'];
$Glass_ASTRO_165WNT = $_POST['Glass_ASTRO_165WNT'];
$Glass_FOL_AJ3015 = $_POST['Glass_FOL_AJ3015'];
$Glass_ACIES_NT = $_POST['Glass_ACIES_NT'];
$Notes = $_POST['Notes'];
$Ship_Preference = $_POST['Ship_Preference'];
// 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', 'jgreeninger@amada.com');
// Set parameters of the email
$to = "ravila@amada.com";
$subject = "Amada Promo Items Ordered";
$from = " jgreeninger@amada.com";
$headers = "CC: ravila@amada.com";
$message = "";
$message .= date("m-d-Y\n");
$message .= "Order has been placed.
Items:\n";
foreach ($_POST as $fieldName => $fieldValue){
if (!empty($fieldValue))
$message .= " $fieldName: $fieldValue\n";
}
$message .= "A quote will be forwarded to
Joe Greeninger before order is placed.\n";
$message = str_replace("_"," ",$message);
// Mail function that sends the email.
mail($to,$subject,$message,$footer,$headers);
$fp = fopen("latc.txt", "a");
fwrite($fp, $message."\r\n");
fclose($fp);
header('Location: index.html');
?>
答案 0 :(得分:2)
更改事物的顺序,以便在将该行添加到邮件之前编写文件:
foreach ($_POST as $fieldName => $fieldValue){
if (!empty($fieldValue))
$message .= " $fieldName: $fieldValue\n";
}
$message = str_replace("_"," ",$message);
$fp = fopen("latc.txt", "a");
fwrite($fp, $message."\r\n");
fclose($fp);
$message .= "A quote will be forwarded to
Joe Greeninger before order is placed.\n";
// Mail function that sends the email.
mail($to,$subject,$message,$footer,$headers);
答案 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'];
$Plastic_Literature_Bag = $_POST['Plastic_Literature_Bag'];
$Amada_Bag = $_POST['Amada_bag'];
$Candy = $_POST['Candy'];
$Moist_Towlette = $_POST['Moist_Towlette'];
$Notepad_and_Pen = $_POST['Notepad_and_Pen'];
$Tuck_Box = $_POST['Tuck_Box'];
$Amada_Tie = $_POST['Amada_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'];
$Glass_LC2415_NT = $_POST['Glass_LC2415_NT'];
$Glass_FOM2NTRI = $_POST['Glass_FOM2NTRI'];
$Glass_ASTRO_165WNT = $_POST['Glass_ASTRO_165WNT'];
$Glass_FOL_AJ3015 = $_POST['Glass_FOL_AJ3015'];
$Glass_ACIES_NT = $_POST['Glass_ACIES_NT'];
$Notes = $_POST['Notes'];
$Ship_Preference = $_POST['Ship_Preference'];
// 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', 'jgreeninger@amada.com');
// Set parameters of the email
$to = "ravila@amada.com";
$subject = "Amada Promo Items Ordered";
$from = " jgreeninger@amada.com";
$headers = "CC: ravila@amada.com";
$message = "";
$message .= date("m-d-Y\n");
$message .= "Order has been placed.
Items:\n";
foreach ($_POST as $fieldName => $fieldValue){
if (!empty($fieldValue))
$message .= " $fieldName: $fieldValue\n";
}
$message = str_replace("_"," ",$message);
// Mail function that sends the email.
$mailMsg = $message . " A quote will be forwarded to Joe Greeninger before order is placed.\n";
mail($to,$subject,$mailMsg,$footer,$headers);
$fp = fopen("latc.txt", "a");
fwrite($fp, $message."\r\n");
fclose($fp);
header('Location: index.html');
?>