1

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('dinesh224401@gmail.com', 'Dinesh Laravel');

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

    });

where $emailIds have 'dinesh.rkgit@rediffmail.com', 'anu.rkgit@rediffmail.com' but I am getting this error:

Address in mailbox given ['abc1@rediffmail.com', 'abc@rediffmail.com'] does not comply with RFC 2822, 3.6.2.

if I use directly emails in mail function like this:

$message->to('abc1@rediffmail.com', 'abc@rediffmail.com')

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

$aa=implode("', '",array('dinesh.rkgit@rediffmail.com', 'anu.rkgit@rediffmail.com'));
     //print_r("'".$aa."'");
$emailIds="['".$aa."']";   //I have used [] here but it did not work also
echo $emailIds
//output ['dinesh.rkgit@rediffmail.com', 'anu.rkgit@rediffmail.com'] 

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

Dinesh
  • 4,066
  • 5
  • 21
  • 35
  • Possible duplicate of [Address in mailbox given \[\] does not comply with RFC 2822, 3.6.2. when email is in a variable](http://stackoverflow.com/questions/21530566/address-in-mailbox-given-does-not-comply-with-rfc-2822-3-6-2-when-email-is) – Andy Holmes Mar 09 '16 at 13:24
  • Sorry Andy, but my question is for multiple recipients and for single recipient there is no problem at my side too. – Dinesh Mar 09 '16 at 15:15

1 Answers1

1

Because, $emailIds = 'dinesh.rkgit@rediffmail.com', 'anu.rkgit@rediffmail.com'; is a string, comma separaed.

the to method of Mail requires an array.

Try this:

$emailIds = ['dinesh.rkgit@rediffmail.com', 'anu.rkgit@rediffmail.com'];
$d=Mail::send('admin.email_template', $data, function ($message) use ($data,$emailIds) {

        $message->from('dinesh224401@gmail.com', 'Dinesh Laravel');

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

    });
Latheesan
  • 23,247
  • 32
  • 107
  • 201
  • thanks for your answer Latheesan, I am making this string from array and I already tried it. Just see, I have updated my question. – Dinesh Mar 09 '16 at 15:05