PHP 联系表单 - 基于所选表单值的动态电子邮件列表



我需要将多个电子邮件地址动态添加到联系表单发送的电子邮件的抄送:字段中。抄送中的电子邮件:应根据选定的表单下拉值添加。表单中有多个下拉列表,每个值都分配了大量电子邮件。

电子邮件的接收者是一个将自动打开工单的系统,因此 To: 字段将只有 1 个硬编码的电子邮件地址。但根据其他值(paltform 和优先级(,需要通知不同的利益相关者此电子邮件已发送到系统。例如:

<tr>
<td valign="top">
<label for="priority"> Priority:</label>
</td>
<td valign="top">
<select name="priority">
<option value="3">Normal</option>
<option value="2">High</option>
<option value="1">Critical</option>
</td>
</select>
</tr>
<tr>
<td valign="top">
<label for="platform">Platform:</label>
</td>
<td valign="top">
<select name="platform">
<option value="windows">Windows</option>
<option value="mac">MAC</option>
<option value="ios">iOS</option>
<option value="android">Android</option>
</td>
</select>
</tr>

如果优先级=1(电子邮件1,电子邮件2,电子邮件3(和平台=窗口(电子邮件4,电子邮件5(,抄送:字段应具有:电子邮件1,电子邮件2,电子邮件3,电子邮件4,电子邮件5。总共有 5 个下拉列表,每个下拉列表有 3 到 7 个值,因此对所有组合进行硬编码是不合理的。

最好的方法是什么?是否最好将变量分配给 Cc: 标头,然后让它从预定义列表中获取电子邮件并将它们组合成字符串?

$to = 'email_address@mail.com' ;     
$subject = strip_tags($_POST['subject']);
$headers  = 'MIME-Version: 1.0' . "rn";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
$headers .= "From: ".$_POST['email']." rn"; 
$headers .= "Cc: ".$_POST['need to compose this part']." rn";

另外,最好将 Cc: 电子邮件的列表保存在脚本之外,以便在不更改代码的情况下更改它们?

我将不胜感激对此的任何帮助。

将您的电子邮件存储在两个数组中: - 第一个优先级数组 - 平台的第二个阵列

$arrPriority = array("email1 email2 email3", "email1 email2 email4", "email1 email3 email4");
$arrPlatform = array("windows" => "email5 email6", "mac" => "email5 email7", "ios" => "email6 email7", "android" => "email5 eamil6");
...
$headers .= "Cc: ".$arrPriority[$_POST['priority']]." ".$arrPlatform[$_POST['platform']]." rn";

发布您的优先级和平台将选择必要的电子邮件抄送组合:

最新更新