PHP邮件程序多个地址

时间:2014-09-08 06:45:30

标签: php phpmailer

当我使用多个地址时,我的php邮件程序功能出现问题。这是我使用的代码:

$message = $_POST['txtMesssage'];
 $mail->SetFrom('my@mydomain.com');
 $mail->AddCC('my@mydomain.com');
 $mail->AddReplyTo("my@mydomain.com");
 $mail->Subject    = $_POST['txtSubject'];
 $mail->Body = $message;
  $mail->IsHTML(true);
 $address = $_POST['txtTO'];
$mail->AddAddress($address);

文本TO就像:

  

A·B @ yourdomain.com,b.b @ yourdomain.com,C.B @ yourdomain.com,   d.b@yourdomain.com,   e.b @ yourdomain.com,f.b @ yourdomain.com,g.b @ yourdomain.com

任何想法,我怎么能让它发挥作用?感谢

编辑:

这对我有用:

$addresses = explode(',', $_POST['txtTO']);
    foreach ($addresses as $address) {
    $mail->AddAddress($address);
    }

谢谢!

2 个答案:

答案 0 :(得分:1)

$addresses = explode(',', $_POST['txtTO'];);
foreach ($addresses as $address) {
$mail->AddAddress($address);
}

答案 1 :(得分:0)

尝试使用数组概念,获取所有表单值,我的意思是在数组迭代中发送并发送它。这就像通过for循环向收件人发送单独的邮件一样。

 $Address = array(); 
    $Address[] = $_POST['txtTO']; 
    foreach($Address AS $Add=>$ToEmail){ 
    mail($ToEmail, $Subject, $Message, $mailheaders);