Mailer Yii2: How To send email to multiple Recipient with different Mails (Message)

Hello there, I am new with Yii2.

I need to send email with multiple recipient , and also all the mail that send different each other.

For Example :

Recipient 1 :

Good Evening "Mr. Ganteng ", This is test Email

Recipient 2 :

Good Evening "Mrs. Cantik", This is test Email

Recipient 3 :

Good Evening "Mrs. Imut" , This is test Email

I’ve tried using loop to send, but it’s not work.

Any possible alternative ways…??


How does it not work? Do you get an error message?

Please post the code you wrote to send the emails.

this is my code snippets

public function actionAddRequest() {


foreach ($subject as $subs) {

                    $lecturer = AitkRDosen::findOne($subs->lecturer_id);

                    $message = "Hello Mr/Mrs". $lecturer->name." , This is a Test Mail ";

                    $recipient_email = $lecturer->email;


                    if ($this->Sendmail($message, $recipient_email)) {






And here my function in Controller that send the email

    public function Sendmail($message, $recipient_mail) {

        $email = Yii::$app->mailer->compose()

                ->setFrom([\Yii::$app->params['supportEmail'] => 'SUPPORT'])


                ->setSubject("TEST MAIL")



        return $email;


It’s only work for sending e-mail with 1 recipient, if it more than 1 recipients. The mail not sent to the recipient.

You could do some debugging, check what’s in “$tujuan” when the sending fails.

On a side note: it’s a VERY good practice to write all your code in English, no matter your mother tongue.

Haha, I’m Sorry for that. Now I’ve update the code into simple ways.

Anyway, There is no error in the $recipient_email