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.
For smtp you need to have port number, logon email address and in To:"[email protected];[email protected]" …
Sending an email in Laravel Laravel's creators recommend using one of the API based drivers: Mailgun, SparkPost, or Amazon SES.
public function send_mail()
{
$mails = Joinus::pluck('email')->toArray();
foreach ($mails as $mail)
{
Mail::to($mail)->send((new SendMail(new Joinus($mail)))->delay(30));
};
}
$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.
You can try 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);
}
Thanks,
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With