Laravel Mail::send() sending to multiple to or bcc addresses

前端 未结 10 1175
梦谈多话
梦谈多话 2020-11-28 05:26

I can\'t seem to successfully send to multiple addresses when using Laravel\'s Mail::send() callback, the code does however work when I only sp

相关标签:
10条回答
  • 2020-11-28 06:15

    This works great - i have access to the request object and the email array

            $emails = ['tester@blahdomain.com', 'anotheremail@blahdomian.com'];
            Mail::send('emails.lead', ['name' => $name, 'email' => $email, 'phone' => $phone], function ($message) use ($request, $emails)
            {
                $message->from('no-reply@yourdomain.com', 'Joe Smoe');
    //            $message->to( $request->input('email') );
                $message->to( $emails);
                //Add a subject
                $message->subject("New Email From Your site");
            });
    
    0 讨论(0)
  • 2020-11-28 06:22

    With Laravel 5.6, if you want pass multiple emails with names, you need to pass array of associative arrays. Example pushing multiple recipients into the $to array:

    $to[] = array('email' => $email, 'name' => $name);
    

    Fixed two recipients:

    $to = [['email' => 'user.one@example.com', 'name' => 'User One'], 
           ['email' => 'user.two@example.com', 'name' => 'User Two']];
    

    The 'name' key is not mandatory. You can set it to 'name' => NULL or do not add to the associative array, then only 'email' will be used.

    0 讨论(0)
  • 2020-11-28 06:27

    In a scenario where you intend to push a single email to different recipients at one instance (i.e CC multiple email addresses), the solution below works fine with Laravel 5.4 and above.

    Mail::to('dunsin.olubobokun@domain.com')
        ->cc(['paul.yomi@domain.com','stack.overflow@domain.com','abc.xyz@domain.com','nigeria@domain.com'])
        ->send(new document());
    

    where document is any class that further customizes your email.

    0 讨论(0)
  • 2020-11-28 06:31

    Try this:

    $toemail = explode(',', str_replace(' ', '', $request->toemail));
    
    0 讨论(0)
提交回复
热议问题