根据表单的输入设置PHP变量
testI需要根据用户从HTMLform中的选择框中选择的选项设置一个变量 HTML 如果值=1,则应为根据表单的输入设置PHP变量,php,html,Php,Html,testI需要根据用户从HTMLform中的选择框中选择的选项设置一个变量 HTML 如果值=1,则应为&toenquiries@website.com. 如果值=2,则应为&toproposals@website.com. 如果值=3,则应为&towork@website.com. 我是前端工程师,只懂PHP的基本知识。大部分PHP文件已经编码为发送电子邮件,但我没有看到这个。谢谢 使用开关或如果条件允许 switch ($_GET['department']) { case '1':
&to
enquiries@website.com.
如果值=2,则应为&to
proposals@website.com.
如果值=3,则应为&to
work@website.com.
我是前端工程师,只懂PHP的基本知识。大部分PHP文件已经编码为发送电子邮件,但我没有看到这个。谢谢 使用开关或如果条件允许
switch ($_GET['department']) {
case '1':
$to = "...";
break;
case '2':
$to = "...";
break;
//....
}
您可以创建您的值的映射
$map = array(
0=>"",
1=>"email1@somewhere.com",
2=>"email2@somewhere.com",
3=>"email3@somewhere.com",
4=>"email4@somewhere.com");
然后根据匹配的post值将$to分配给
$to = $map[(int)$_POST["department"]];
下面这样的关联数组怎么样:
$emails = array( "1" => "enquiries@website.com", "2" => "proposals@website.com" , "3" => "work@website.com");
// and then
$to = $emails[$_POST["department"]];
你可以用
<option value="email@mydomain.com">department</option>
部门
然后获取post值。if(…){$to=…}否则if(…){$to=…}…
$emails = array( "1" => "enquiries@website.com", "2" => "proposals@website.com" , "3" => "work@website.com");
// and then
$to = $emails[$_POST["department"]];
switch ($_POST['department']) {
case 1:
$to = 'enquiries@website.com';
break;
case 2:
$to = 'proposals@website.com';
break;
case 3:
$to = 'work@website.com';
break;
}
<option value="email@mydomain.com">department</option>