我目前正在为我工作的公司制作一个简单的PHP联系表单。它包括一些复选框和一些文本区域,这是php代码。
<?php
function getPost($name){
return ( isset($_POST[$name])? $_POST[$name] : '');
}
$name = $_POST['name'];
$email = $_POST['email'];
$email2 = $_POST['email2'];
$landline = $_POST['landline'];
$mobile = $_POST['mobile'];
$pclandline = getPost('pclandline');
$pcmobile = getPost('pcmobile');
$pcemail = getPost('pcemail');
$zptf = getPost('zptf');
$zpf = getPost('zpf');
$zpsf = getPost('zpsf');
$opz = getPost('opz');
$opfg = getPost('opfg');
$opfs = getPost('opfs');
$tpz = getPost('tpz');
$tpf= getPost('tpf');
$zpfoct= getPost('zpfoct');
$opzoct= getPost('opzoct');
$zptfquan = $_POST['zptfquan'];
$zpfquan = $_POST['zpfquan'];
$zpsfquan = $_POST['zpsfquan'];
$opzquan = $_POST['opzquan'];
$opfgquan = $_POST['opfgquan'];
$opfsquan = $_POST['opfsquan'];
$tpzquan = $_POST['tpzquan'];
$tpfquan = $_POST['tpfquan'];
$zpfoctquan = $_POST['zpfoctquan'];
$opzoctquan = $_POST['opzoctquan'];
$promo = $_POST['promo'];
$message = $_POST['message'];
$formcontent=" From: $name \n Email : $email \n Confirm Email : $email2 \n Landline: $landline \n Mobile: $mobile \n PC Landline: $pclandline \n PC Mobile: $pcmobile \n PC Email: $pcemail \n \n 0.25l: $zptf \n 0.25l Quantity: $zptfquan \n 0.5l: $zpf \n 0.5l Quantity: $zpfquan \n 0.75l: $zpsf \n 0.75l Quantity: $zpsfquan \n 1.0l: $opz \n 1.0l Quantity: $opzquan \n 1.5lg: $opfg \n 1.5lg Quantity: $opfgquan \n 1.5ls: $opfs \n 1.5ls Quantity: $opfsquan \n 2.0l: $tpz \n 2.0l Quantity: $tpzquan \n 2.5l: $tpf \n 2.5l Quantity: $tpfquan \n 0.5l Octime: $zpfoct \n 0.5l Octime Quantity: $zpfoctquan \n 1.0l Octime: $opzoct \n 1.0l Octime Quantity: $opzoctquan \n Promotional Code: $promo \n Message: $message";
$recipient = "replaced email";
$subject = "Glass Sweet Jars Quote";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank you! We will contact you as soon as possible with your quote" . " -" . "<a href='index.html'>Return Home</a>";
?>
我的问题是,当我收到电子邮件时,它会在表单上列出所有内容,无论用户是否已经检查或写入,这使得选择相关数据非常耗时,有没有办法隐藏任何区域而不是用户在该特定电子邮件中填写?
提前致谢!
答案 0 :(得分:0)
如果未设置变量,请不要将其添加到$ formcontent ...
答案 1 :(得分:0)
使用empty()检查变量是否已设置并填充。如果为true,则添加到表单变量中,否则忽略..
$formcontent = "";
$formcontent .= !empty($email)? "Email : {$email}<br />" : "";
$formcontent .= !empty($confirmemail)? "Confirm Email : {$confirmemail}<br />" : "";