Dinesh
Dinesh

Reputation: 4110

Sending multiple mail issue with laravel 5

I have users database, and I want to send email to all my one form So I am trying like this:

$d=Mail::send('admin.email_template', $data, function ($message) use ($data,$emailIds) {

        $message->from('[email protected]', 'Dinesh Laravel');

        $message->to($emailIds)->subject($data['subject']);

    });

where $emailIds have '[email protected]', '[email protected]' but I am getting this error:

Address in mailbox given ['[email protected]', '[email protected]'] does not comply with RFC 2822, 3.6.2.

if I use directly emails in mail function like this:

$message->to('[email protected]', '[email protected]')

then it works, Updated: I am making this string from array as:

$aa=implode("', '",array('[email protected]', '[email protected]'));
     //print_r("'".$aa."'");
$emailIds="['".$aa."']";   //I have used [] here but it did not work also
echo $emailIds
//output ['[email protected]', '[email protected]'] 

I do not know what is problem, Thanks in advance.

Upvotes: 1

Views: 583

Answers (1)

Latheesan
Latheesan

Reputation: 24116

Because, $emailIds = '[email protected]', '[email protected]'; is a string, comma separaed.

the to method of Mail requires an array.

Try this:

$emailIds = ['[email protected]', '[email protected]'];
$d=Mail::send('admin.email_template', $data, function ($message) use ($data,$emailIds) {

        $message->from('[email protected]', 'Dinesh Laravel');

        $message->to($emailIds)->subject($data['subject']);

    });

Upvotes: 1

Related Questions