我创建了以下代码,因此当用户选择部门(销售,账单,营销,财务等)并使用我创建的联系表单时,电子邮件将发送给公司中的适当人员。 / p>
<?php
$ip = $_POST['ip'];
$httpref = $_POST['httpref'];
$httpagent = $_POST['httpagent'];
$visitor = $_POST['visitor'];
$visitormail = $_POST['visitormail'];
$notes = $_POST['notes'];
$attn = $_POST['attention'];
$prefphone = $_POST['phone'];
$contact_pref = $_POST['contact'];
$subject = $_POST['subject'];
if (eregi('http:', $notes)) {
die ("Do NOT try that! ! ");
}
if(!$visitormail == "" && (!strstr($visitormail,"@") || !strstr($visitormail,".")))
{
echo "<h2>Use Back - Enter valid e-mail</h2>\n";
$badinput = "<h2>Feedback was NOT submitted</h2>\n";
echo $badinput;
die ("Go back! ! ");
}
if(empty($visitor) || empty($visitormail) || empty($notes )) {
echo "<h2>Use Back - fill in all fields</h2>\n";
die ("Use back! ! ");
}
$todayis = date("l, F j, Y, g:i a") ;
$attention = $attention ;
$subject = $attention;
$notes = stripcslashes($notes);
$message = " $todayis [EST] \n
Attention: $attn \n
From: $visitor ($visitormail)\n
Please contact me by: $contact \n
Phone Number: $phone \n
Subject: $subject \n
Message: $notes \n
Additional Info : IP = $ip \n
Browser Info: $httpagent \n
Referral : $httpref \n
";
$from = "From: $visitormail\r\n";
switch ($attention) {
case "Residential":
mail("mike@company.com", $subject, $message, $from);
break;
case "Billing":
mail("mike@company.com", $subject, $message, $from);
break;
case "Service":
mail("service@company.com", $subject, $message, $from);
break;
case "Technical":
mail("service@company.com", $subject, $message, $from);
break;
}
?>
当客户收到电子邮件时,from:字段说明发件人的电子邮件,这对除技术支持部门以外的所有部门都是好的。这个部门需要事先了解发件人的电子邮件,因此我需要对其进行编码,以便在选择技术选项并收到电子邮件时,该地址是默认地址(即technical@company.com)。
不确定如何执行此操作以及是否可以使用switch / case语句完成此操作?
答案 0 :(得分:0)
我可能只是在这里遗漏了一些东西,但你不能只是替换:
case "Technical":
mail("service@company.com", $subject, $message, $from);
break;
带
case "Technical":
mail("service@company.com", $subject, $message, $technical_emailaddress);
break;
在开关案例中?