PHP邮件程序多个地址

标签 php phpmailer

Possible Duplicate: PHPMailer AddAddress()

这是我的代码。

require('class.phpmailer.php');
$mail = new PHPMailer();

$email = 'email1@test.example, email2@test.example, email3@test.example';

    $sendmail = "$email";

    $mail->AddAddress($sendmail,"Subject");
    $mail->Subject = "Subject";
    $mail->Body    = $content;

    if(!$mail->Send()) { # sending mail failed
        $msg="Unknown Error has Occured. Please try again Later.";
    }
    else {
        $msg="Your Message has been sent. We'll keep in touch with you soon.";
    }
}

问题
如果 $email 值只有 1。它会发送。但多个不发送。我应该为此做些什么。我知道在邮件功能中,您必须用逗号分隔多封电子邮件。但不能在 phpmailer 中工作。

最佳答案

您需要为每个收件人调用一次 AddAddress 方法。像这样:

$mail->AddAddress('person1@domain.example', 'Person One');
$mail->AddAddress('person2@domain.example', 'Person Two');
// ..

更好的是,将他们添加为抄送收件人。

$mail->AddCC('person1@domain.example', 'Person One');
$mail->AddCC('person2@domain.example', 'Person Two');
// ..

为方便起见,您应该循环遍历一个数组来执行此操作。

$recipients = array(
   'person1@domain.example' => 'Person One',
   'person2@domain.example' => 'Person Two',
   // ..
);
foreach($recipients as $email => $name)
{
   $mail->AddCC($email, $name);
}

关于PHP邮件程序多个地址,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3149452/

相关文章:

javascript - 如何在 iframe src 中嵌入登录凭据?

PHPMailer 发送双重电子邮件

javascript - 无法将 jquery 数据 POST 到 phpmailer

PHPMailer 发送邮件但客户端收不到

PHP exec() 和路径中的空格

PHP 在 NFS 共享目录中创建空 session

php - 错误 : Class 'PHPMailer' not found

amazon-web-services - AWS SES 与 PHPMailer 使用 SMTP,SMTP 错误 : Could not authenticate?

php - JQuery fomdata 将空数据发送到 php 文件?

php - 使用 CodeKit 和 haml/PHP