Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending Mail to Multiple Recipients using laravel 5.4

I am trying to send mails to multiple recipients,But i got an error like

Swift_RfcComplianceException in MailboxHeader.php line 345: Address in mailbox given [[email protected], [email protected], [email protected]] does not comply with RFC 2822, 3.6.2.

but the code does however work when I only specify one recipient.

Here is my code:

Controller :

$myEmail='[email protected], [email protected]';
 $dataArray['name'] ='name';
            $dataArray['E_id'] = 011;
            $dataArray['password'] = '1234';
            $dataArray['username'] = 'test';

            Mail::to($myEmail)->send(new HeadMail($dataArray));

HeadMail.php(inside app folder)

public function build() {

        $address = '[email protected]';
        $name = 'test TEAM';
        $subject = 'USER CREDENTIALS';


        return $this->view('emails.index')
                ->from($address, $name)
                ->cc($address, $name)
                ->bcc($address, $name)
                ->replyTo($address, $name)
                ->subject($subject)
               ->with([
                        'name' => $this->dataArray['name'],
                        'password' => $this->dataArray['password'],
                        'E_id' => $this->dataArray['E_id'],
                        'email' => $this->dataArray['username'],


                    ]);

    }

How can I send the email to all recipients?Please help me.

like image 202
Shanu k k Avatar asked Dec 08 '25 08:12

Shanu k k


1 Answers

Separate emails with a comma and use a simpler solution. At least, this is what I do:

Mail::send(['blade.view.html', 'blade.view.txt'], ['title' => $subject, 'content' => $content], function ($message) {
    $message->from('[email protected]', 'IT Serviss');
    $message->to(explode(",", $client_email_array));
    $message->subject($subject);
});
like image 91
Peon Avatar answered Dec 11 '25 00:12

Peon



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!