phplaravelemaillaravel-5eloquent

Laravel 5 sending mail to multiple users at once


I am trying to sending mails to all users. But i can't figure out how to make this. In my controller, i made this.

public function send_mail()
{
    $mails = Joinus::all();
    $array = array();
    $allmails = array();
    foreach ($mails as $mail)
    {
        $allmails = array_push($array, $mail->email);

    };
    Mail::to($allmails)->send((new SendMail(new Joinus('email')))->delay(30));
}

I am getting all types of error. Last one is

__construct() must be of the type array

In my SendMail.php

public function __construct($email)
{
    $this->email = $email;
}

I wasted my one day and can't make. I am very grateful for your help. Thanks an advance.


Solution

  • $allmails = array_push($array, $mail->email); is wrong

    Right answer is just array_push($array, $mail->email);

    array_push($array, $mail->email); this is returning an array.

    $allmails = array_push($array, $mail->email); But this is returning int value.