Reputation: 2063
Q : How can I send multiple addresses at once?
status : I am using the mailer extension. It is working when I send to single address. But when I send to multiple addresses. It isn't working.
This one is working.
$mailer->AddAddress("[email protected]");
followings are not working.
$mailer->AddAddress("[email protected], [email protected]");
$mailer->AddAddress("'[email protected]', '[email protected]'");
$mailer->AddAddress("\"[email protected]\", \"[email protected]\"");
Upvotes: 2
Views: 4218
Reputation: 33
Simple way to understand single email...
$emailaddress="[email protected]"
$username="John Doe"
$mail->AddAddress($emailaddress,$username);
For multiple emails...
$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");
Or you needs multiple emails in arrays...
foreach ($array as $value) {
$mail->AddAddress($array[$value]);
}
and in any loop condition that meet your requirement.
Upvotes: 0
Reputation: 3070
Modify the Mailer class as following. 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();
}
}
}
?>
Upvotes: 0
Reputation: 8408
You just have to call the "addAddress" function multiple times:
$mailer->AddAddress("[email protected]");
$mailer->AddAddress("[email protected]");
Upvotes: 4