2

问:如何一次发送多个地址?

状态:我正在使用邮件扩展。当我发送到单个地址时它正在工作。但是当我发送到多个地址时。它不工作。

这个正在工作。

$mailer->AddAddress("aa@gmail.com");

以下不工作。

$mailer->AddAddress("aaa@gmail.com, bbbb@gmail.com");
$mailer->AddAddress("'aaa@gmail.com', 'bbbb@gmail.com'");
$mailer->AddAddress("\"aaa@gmail.com\", \"bbbb@gmail.com\"");
4

4 回答 4

4

您只需多次调用“addAddress”函数:

$mailer->AddAddress("aaa@gmail.com");
$mailer->AddAddress("bbbb@gmail.com");
于 2012-09-04T05:32:17.707 回答
0

修改 Mailer 类如下。访问此线程以获取更多信息

<?php

Yii::import('application.extensions.PHPMailer_v5.1.*');

class Mailer {

    private $mail;

    public function initialise() {
        try {
            require Yii::getPathOfAlias('application.extensions') . '/PHPMailer_v5.1/class.phpmailer.php';
            $this->mail = new PHPMailer(TRUE);
            $this->mail->IsSMTP();                           // tell the class to use SMTP
            $this->mail->SMTPDebug = 0;
            $this->mail->SMTPAuth = true;                  // enable SMTP authentication
            $this->mail->Port = 25;                    // set the SMTP server port
            $this->mail->Host = "smtp.test.net"; // SMTP server
            $this->mail->Username = "test.com";      // SMTP server username
            $this->mail->Password = "test";            // SMTP server password
            $this->mail->Mailer = "smtp";
            $this->mail->From = 'info@test.com';
            $this->mail->FromName = 'test@net.com';
        } catch (Exception $e) {
            echo $e->getTraceAsString();
        }
    }

    public function email($message, $sendTo, $subject) {
        try {
            $this->mail->AddAddress($sendTo);
            $this->mail->Subject = $subject;
            $body = $message;
            $this->mail->MsgHTML($body);
            $this->mail->IsHTML(true); // send as HTML
            $this->mail->Send();
            $this->mail->ClearAllRecipients();
        } catch (Exception $e) {
            echo $e->getTraceAsString();
        }
    }

}

?>
于 2012-09-04T07:13:03.020 回答
0

理解单个电子邮件的简单方法...

$emailaddress="johndoe@domain.com"
$username="John Doe"

$mail->AddAddress($emailaddress,$username);

对于多个电子邮件...

$mail->AddAddress("johndoe@domain.com");
$mail->AddAddress("johnsmith@domain.com");

或者您需要数组中的多封电子邮件...

foreach ($array as $value) {

$mail->AddAddress($array[$value]);

}

并在满足您要求的任何循环条件下。

于 2013-02-22T15:10:10.760 回答
-1

此外,您可以通过 Yii::app->mailer->newMessage. 创建消息。这允许您设置电子邮件消息值。例如:

$emailAddresses = array(
    'to'    => array('email@blah.com','email2@blah.com'),
    'bcc'   => array('multiple emails','separated','by','commas'),
    'reply' => $replyEmail,
);

// Generate the message with appropriate fields
$message = Yii::app->mailer->newMessage; //Swift_Message::newInstance()
$message->setSubject($subject);
$message->setFrom(array($emailAddress => 'administration'));
$message->setTo( $emailAddresses['to'] );
$message->setBcc( $emailAddresses['bcc'] );
$message->setReplyTo( $emailAddresses['reply'] );
$message->setBody('<h1>'.$header.'</h1><p>'.$bodyHtml,'text/html');

//Send message
$mailer = Yii::app()->mailer->getInstance($email);

$mailer->send($message,$failures);
于 2016-09-14T16:07:11.540 回答