2011-01-24 176 views
0

我试图循环选择下拉菜单并发送电子邮件给多个收件人。每次添加逗号来添加多个电子邮件时,表单都会失败。 下面是我正在使用的代码块,但我想添加更多的电子邮件地址为'recipient_1'2和3,用逗号分隔。php电子邮件多个收件人

$recipients = array(
'recipient_1' => '[email protected], 
'recipient_2' => '[email protected]', 
'recipient_3' => '[email protected]' 
); 


$to = $recipients[$_REQUEST['recipient']]; 


mail($to, $subject, $body, $headers); 



<select name="recipient" id="location" tabindex="20"> 
     <option value="-1">--- Please Select ---</option> 
     <option value="recipient_1">City 1</option> 
     <option value="recipient_2">City 2</option> 
     <option value="recipient_3">City 3</option> 
     </select> 
+0

在你的数组你错过了“”周围[email protected],对于初学者。也许只是复制粘贴的东西... – hade 2011-01-24 12:13:32

+0

这实际上只是一个错误复制和粘贴到此网站上,我确实在我的代码中有单引号后[email protected] – cam 2011-01-24 12:28:10

回答

2

你是第一个recipient_1后缺少右引号:

'recipient_1' => '[email protected], 
            ^--here 

这会导致一个语法错误。

+0

这实际上只是一个错误复制并粘贴到此我的代码中有单引号[email protected] – cam 2011-01-24 12:30:04

0

我创造了这样的使用JavaScript的东西..看看我的例子here

相关问题