我的学校网站衬衫订单有一个很长的订单。我们提供多种不同的选择供peopel选择。我收到订单电子邮件,但它们很长,包含每个项目的名称。如何收到仅包含订购商品的电子邮件,而不是整个表格,其中列出了所有商品但没有订购?
PHP操作代码:
<?php
//Form Action
$_POST['emailAddress'] = "PCLA Registrar<regsitration@paragonlearningacademy.com>";
$to = 'PCLA Registrar<rxxx.com>' . ', ';
$to .= "{$_POST['email']}\r\n";
$subject = '2016-2017 Shirt Order Form';
//Parent Information
$message = "Parents Name: {$_POST['parents_name']}\r\n";
$message = "Students Name: {$_POST['students_name']}\r\n";
$message .= "Email Address: {$_POST['email']}\r\n";
$message .= "Phones Number: {$_POST['phone_number']}\r\n";
//Short Sleeve T-Shirts
$message .= "Short Youth Small: {$_POST['short_youth_small']}\r\n";
$message .= "Short Youth Medium:{$_POST['short_youth_medium']}\r\n";
$message .= "Short Youth Large: {$_POST['short_youth_large']}\r\n";
$message .= "Short Youth XL: {$_POST['short_youth_xl']}\r\n";
$message .= "Short Adult Small: {$_POST['short_adult_small']}\r\n";
$message .= "Short Adult Medium:{$_POST['short_adult_medium']}\r\n";
$message .= "Short Adult Large: {$_POST['short_adult_large']}\r\n";
$message .= "Short Adult XL: {$_POST['short_adult_xl']}\r\n";
$message .= "Short Adult 2XL: {$_POST['short_adult_2xl']}\r\n";
$message .= "Short Adult 3XL: {$_POST['short_adult_3xl']}\r\n";
$message .= "Total Ordered: {$_POST['tshirts_ordered']}\r\n";
$message .= "Total Amount Due: {$_POST['short_amount_due']}\r\n";
// Long Sleeve T-Shirts
$message .= "Long Youth Small: {$_POST['long_youth_s']}\r\n";
$message .= "Long Youth Medium: {$_POST['long_youth_m']}\r\n";
$message .= "Long Youth Large: {$_POST['long_youth_large']}\r\n";
$message .= "Long Youth XL: {$_POST['long_youth_xl']}\r\n";
$message .= "Long Adult Small: {$_POST['long_adult_s']}\r\n";
$message .= "Long Adult Medium: {$_POST['long_adult_m']}\r\n";
$message .= "Long Adult Large: {$_POST['long_adult_large']}\r\n";
$message .= "Long Adult XL: {$_POST['long_adult_xl']}\r\n";
$message .= "Long Adult 2XL: {$_POST['long_adult_2xl']}\r\n";
$message .= "Total Ordered: {$_POST['long_ordered']}\r\n";
$message .= "Total Amount Due: {$_POST['long_amount_due']}\r\n";
// Sweatshirts
$message .= "Sweatshirt Youth Small: {$_POST['long_youth_s']}\r\n";
$message .= "Sweatshirt Youth Medium: {$_POST['long_youth_m']}\r\n";
$message .= "Sweatshirt Youth Large: {$_POST['long_youth_large']}\r\n";
$message .= "Sweatshirt Youth XL: {$_POST['long_youth_xl']}\r\n";
$message .= "Sweatshirt Adult Small: {$_POST['sweat_adult_s']}\r\n";
$message .= "Sweatshirt Adult Medium:{$_POST['sweat_adult_m']}\r\n";
$message .= "Sweatshirt Adult Large:{$_POST['sweat_adult_large']}\r\n";
$message .= "Sweatshirt Adult XL: {$_POST['sweat_adult_xl']}\r\n";
$message .= "Sweatshirt Adult 2XL: {$_POST['sweat_adult_2xl']}\r\n";
$message .= "Sweatshirt Adult 3XL: {$_POST['sweat_adult_3xl']}\r\n";
$message .= "Total Ordered: {$_POST['sweat_ordered']}\r\n";
$message .= "Total Amount Due: {$_POST['sweat_amount_due']}\r\n";
// Hooded Sweatshirt
$message .= "Hooded Youth Small: {$_POST['hooded_youth_s']}\r\n";
$message .= "Hooded Youth Medium: {$_POST['hooded_youth_m']}\r\n";
$message .= "Hooded Youth Large: {$_POST['hooded_youth_large']}\r\n";
$message .= "Hooded Youth XL: {$_POST['hooded_youth_xl']}\r\n";
$message .= "Hooded Adult Small: {$_POST['hooded_adult_s']}\r\n";
$message .= "Hooded Adult Medium: {$_POST['hooded_adult_m']}\r\n";
$message .= "Hooded Adult Large: {$_POST['hooded_adult_large']}\r\n";
$message .= "Hooded Adult XL: {$_POST['hooded_adult_xl']}\r\n";
$message .= "Hooded Adult 2XL: {$_POST['hooded_adult_2xl']}\r\n";
$message .= "Hooded Adult 3XL: {$_POST['hooded_adult_3xl']}\r\n";
$message .= "Total Ordered: {$_POST['hooded_ordered']}\r\n";
$message .= "Total Amount Due: {$_POST['hooded_amount_due']}\r\n";
// Zip Up Hooded Jacket
$message .= "Zip Up Youth Small: {$_POST['zip_up_youth_s']}\r\n";
$message .= "Zip Up Youth Medium: {$_POST['zip_up_youth_m']}\r\n";
$message .= "Zip Up Youth Large: {$_POST['zip_up_youth_large']}\r\n";
$message .= "Zip Up Youth XL: {$_POST['zip_up_youth_xl']}\r\n";
$message .= "Zip Up Adult Small: {$_POST['zip_up_adult_s']}\r\n";
$message .= "Zip Up Adult Medium: {$_POST['zip_up_adult_m']}\r\n";
$message .= "Zip Up Adult Large: {$_POST['zip_up_adult_large']}\r\n";
$message .= "Zip Up Adult XL: {$_POST['zip_up_adult_xl']}\r\n";
$message .= "Zip Up Adult 2XL: {$_POST['zip_up_adult_2xl']}\r\n";
$message .= "Zip Up Adult 3XL: {$_POST['zip_up_adult_3xl']}\r\n";
$message .= "Total Ordered: {$_POST['zip_up_ordered']}\r\n";
$message .= "Total Amount Due: {$_POST['zip_up_amount_due']}\r\n";
// Polo
$message .= "Polo Youth Small: {$_POST['polo_youth_s']}\r\n";
$message .= "Polo Youth Medium: {$_POST['polo_youth_m']}\r\n";
$message .= "Polo Youth Large: {$_POST['polo_youth_large']}\r\n";
$message .= "Polo Youth XL: {$_POST['polo_youth_xl']}\r\n";
$message .= "Women's Polo Small: {$_POST['wpolo_s']}\r\n";
$message .= "Women's Polo Medium: {$_POST['wpolo_m']}\r\n";
$message .= "Women's Polo Large: {$_POST['wpolo_large']}\r\n";
$message .= "Women's Polo XL: {$_POST['wpolo_xl']}\r\n";
$message .= "Men's Polo Small: {$_POST['mpolo_s']}\r\n";
$message .= "Men's Polo Medium: {$_POST['mpolo_m']}\r\n";
$message .= "Men's Polo Large: {$_POST['mpolo_large']}\r\n";
$message .= "Men's Polo XL: {$_POST['mpolo_xl']}\r\n";
$message .= "Men's Polo 2XL: {$_POST['mpolo_2xl']}\r\n";
$message .= "Men's Polo 3XL: {$_POST['mpolo_2xl']}\r\n";
$message .= "Total Ordered: {$_POST['polo_ordered']}\r\n";
$message .= "Total Amount Due: {$_POST['polo_amount_due']}\r\n";
//Totals
$message .= "Total Amount Ordered: {$_POST['total_ordered']}\r\n";
$message .= "Total Amount Due: {$_POST['total_amount']}\r\n";
//General Agreements
$message .= "Shirts Required: {$_POST['shirts']}\r\n";
$message .= "Exchanges: {$_POST['exchange']}\r\n";
$message .= "Payment: {$_POST['payment']}\r\n";
if ($_POST['comments_questions']) {
$message .= "Comments: {$_POST['comments_questions']}\r\n";
}
$headers = "From: " . $_POST['emailAddress'] . "\n";
$headers .= "X-Mailer: PHP/".phpversion();
mail($to,$subject,$message,$headers,$additional_headers);
header("Location: http://www.paragonlearningacademy.com/shirt_thanks.htm");
exit;
?>
答案 0 :(得分:1)
注意!您的订单可用于发送垃圾邮件,因为每个人都可以修改电子邮件标题。您必须过滤$ _POST [&#39; emailAddress&#39;]变量。
if ($_POST['short_youth_small']) {
$message .= "Short Youth Small: {$_POST['short_youth_small']}\r\n";
}
if ($_POST['short_youth_medium']) {
$message .= "Short Youth Medium:{$_POST['short_youth_medium']}\r\n";
}
最简单的方法是为每个项添加一个简单的if条件:
$_POST['emailAddress'] = strtr(trim($_POST['emailAddress']), array("\n"=>'', "\r" => ''));
//Form Action
$_POST['emailAddress'] = "PCLA Registrar<regsitration@paragonlearningacademy.com>";
$to = 'PCLA Registrar<registration@paragonlearningacademy.com>' . ', ';
$to .= "{$_POST['email']}\r\n";
$subject = '2016-2017 Shirt Order Form';
//Parent Information
$message = "Parents Name: {$_POST['parents_name']}\r\n";
$message = "Students Name: {$_POST['students_name']}\r\n";
$message .= "Email Address: {$_POST['email']}\r\n";
$message .= "Phones Number: {$_POST['phone_number']}\r\n";
$fields = array (
// variable name => title
'short_youth_small' => 'Short Youth Small',
'short_youth_medium' => 'Short Youth Medium',
// other variables ...
);
// walk the array
foreach ($fields as $key => $title) {
if ($_POST[$key]) {
$message .= $title . ": " . $_POST[$key] . "\r\n";
}
}
//General Agreements
$message .= "Shirts Required: {$_POST['shirts']}\r\n";
$message .= "Exchanges: {$_POST['exchange']}\r\n";
$message .= "Payment: {$_POST['payment']}\r\n";
if ($_POST['comments_questions']) {
$message .= "Comments: {$_POST['comments_questions']}\r\n";
}
$headers = "From: " . $_POST['emailAddress'] . "\n";
$headers .= "X-Mailer: PHP/".phpversion();
mail($to,$subject,$message,$headers,$additional_headers);
header("Location: http://www.example.com/shirt_thanks.htm");
exit;
您必须在每个条件中调整变量的名称,例如括号内的文本
将所有不同的变量放在数组中并使用foreach(...)遍历数组会更好。
例如:
var code = (e.keyCode ? e.keyCode : e.which);
var input = document.getElementById("text");
if (code == 13) {
if (input == "Hungarian" || "Magyar") {
window.open(Lang / hungarian / hungarian.html)
}
}
<p>
<mark class="smallwhite">Type in the desired language:</mark>
</p>
<input type="text" id="input" size="26">
答案 1 :(得分:0)
将if消息中的每个$消息包含在仅包含数据的块中。
示例强>
if("" != trim($_POST['long_adult_large']) {
$message .= "Long Adult Large: {$_POST['long_adult_large']}\r\n";
}