2012-09-04 73 views
1

問:我怎樣才能一次發送多個地址?yii郵件程序擴展:如何一次發送多個郵件地址

status:我正在使用郵件程序擴展。當我發送到單個地址時它正在工作。但是當我發送到多個地址。它不工作。

這是一個工作。

$mailer->AddAddress("[email protected]"); 

以下情況不起作用。

$mailer->AddAddress("[email protected], [email protected]"); 
$mailer->AddAddress("'[email protected]', '[email protected]'"); 
$mailer->AddAddress("\"[email protected]\", \"[email protected]\""); 

回答

0

修改梅勒類如下。 Visit this thread for more information

<?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 = '[email protected]'; 
      $this->mail->FromName = '[email protected]'; 
     } 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(); 
     } 
    } 

} 

?> 
0

簡單的方法來了解單個電子郵件...

$emailaddress="[email protected]" 
$username="John Doe" 

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

對於多個電子郵件...

$mail->AddAddress("[email protected]"); 
$mail->AddAddress("[email protected]"); 

或者你需要在陣列中的多個電子郵件...

foreach ($array as $value) { 

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

} 

並在滿足您的要求的任何環路條件。

-1

此外,您可以通過Yii :: app-> mailer-> newMessage創建消息。 這允許您設置電子郵件消息值。 例如:

$emailAddresses = array(
    'to' => array('[email protected]','[email protected]'), 
    '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); 
相關問題