【问题标题】:Are switch case statements flexible?switch case 语句是否灵活?
【发布时间】:2009-12-15 15:18:13
【问题描述】:

我创建了以下代码,因此当用户选择一个部门(销售、计费、营销、财务等)并使用我创建的联系表时,电子邮件将发送给公司中的适当人员。

<?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;
}

?>

当客户收到电子邮件时,发件人:字段会显示发件人的电子邮件,这适用于除技术支持部门以外的所有部门。该部门需要事先知道发件人的电子邮件,因此我需要对其进行编码,以便在选择技术选项并且他们收到电子邮件时,该地址是默认地址(即 Technical@company.com)。

不确定如何执行此操作以及是否可以使用 switch/case 语句完成此操作?

【问题讨论】:

    标签: php switch-statement


    【解决方案1】:

    我可能只是在这里遗漏了一些东西,但你能不能只替换:

    case "Technical":
            mail("service@company.com", $subject, $message, $from);
            break;
    

    case "Technical":
            mail("service@company.com", $subject, $message, $technical_emailaddress);
            break;
    

    在开关盒内?

    【讨论】:

    • 谢谢!我是新手,因此我不确定在哪里以及如何声明 $technical_emailaddress 等于什么。我在顶部尝试过,如下所示......但这不起作用 $ip = $_POST['ip']; $httpref = $_POST['httpref']; $httpagent = $_POST['httpagent']; $visitor = $_POST['visitor']; $visitormail = $_POST['visitormail']; $notes = $_POST['notes']; $attn = $_POST['注意']; $prefphone = $_POST['phone']; $contact_pref = $_POST['contact']; $subject = $_POST['subject']; $technical_emailaddress = $_POST['technical@company.com'];感谢帮助!欢呼,追逐者
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-09-24
    • 2018-09-10
    • 1970-01-01
    • 2011-08-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多