geeta
geeta

Reputation: 25

How to send mail to multiple recipients in Yii mailer

How to send mail to multiple recipients in Yii mailer?

This code is working for a single recipient but not for multiple recipients.

$mail_ids = $_POST['invitefriend'];
                $name = Yii::app()->user->getName();
                $mail = new YiiMailer();
                $mail->setFrom(Yii::app()->params['mailFrom'], $name);
                $mail->setTo($mail_ids);
                $mail->setSubject('Mail subject');
                $mail->setBody('Simple message');
                $mail->send();

Thanks in advance!

Upvotes: 2

Views: 3945

Answers (1)

Ulug'bek
Ulug'bek

Reputation: 2832

In Yii Mailer documantation was written like that : Setting addresses

When using methods for setting addresses (setTo(), setCc(), setBcc(), setReplyTo()) any of the following is valid for arguments:

$mail->setTo('[email protected]');
$mail->setTo(array('[email protected]','[email protected]'));
$mail->setTo(array('[email protected]'=>'John Doe','[email protected]'));

If your $mail_ids is a string veriable like '[email protected] , [email protected]' you can parse by explode For example:

$emails = explode(',' , $mail_ids);
$mail->setTo($emails);

Upvotes: 3

Related Questions