简体   繁体   English

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

[英]PHP contact form - dynamic email list based on selected form values

I need to dynamically add multiple email addresses to the Cc: field of the email sent by a contact form. 我需要向联系表单发送的电子邮件的“抄送:”字段中动态添加多个电子邮件地址。 Emails in Cc: should be added based on selected form drop-down values. 抄送:中的电子邮件应基于选定的表单下拉值添加。 There are multiple drop-downs in the form, and each value has a number of emails assigned to it. 表单中有多个下拉菜单,每个值都有分配给它的电子邮件数量。

The recepient of the email is a system that will auto-open a ticket, so the To: field will only have 1 hardcoded email address. 电子邮件的接收方是将自动打开故障单的系统,因此“收件人:”字段将只有1个硬编码的电子邮件地址。 But based on other values (paltform and priority), different stakeholders need to be informed that this email has been sent to the system. 但是基于其他值(格式和优先级),需要告知不同的利益相关者该电子邮件已发送到系统。 Eg: 例如:

<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>

If priority=1 (email1,email2,email3) and platform=windows (email4,email5), the Cc: field should have: email1,email2,email3,email4,email5. 如果priority = 1(电子邮件1,email2,email3)和平台= windows(电子邮件4,email5),则抄送:字段应具有:电子邮件1,电子邮件2,电子邮件3,电子邮件4,电子邮件5。 There are in total 5 drop-downs with 3 to 7 values each, so hardcoding all combinations is not reasonable. 共有5个下拉菜单,每个下拉菜单都有3到7个值,因此对所有组合进行硬编码是不合理的。

What is the best way of doing it? 最好的方法是什么? Is it best to assign a variable to the Cc: header, and then make it fetch emails from pre-defined lists and compose them to a string? 最好将一个变量分配给Cc:标头,然后使其从预定义列表中提取电子邮件并将其组合为字符串吗?

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

Also, would it be best to save the list of the Cc: emails outside the script, so they can be changed without changing the code? 另外,最好将Cc:电子邮件的列表保存在脚本之外,以便可以在不更改代码的情况下对其进行更改吗?

I'd appreciate any help with this. 我将不胜感激。

Store your email in two arrays: - first array for priority - second array for platform 将您的电子邮件存储在两个数组中:-第一个数组用于优先级-第二个数组用于平台

$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']]." \r\n";

Posting your priority and platform will chose necessary combination of emails Cc: 发布您的优先级和平台将选择电子邮件抄送的必要组合:

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM