Skip to content

[7.x] Let mailables accept a simple array of email addresses as cc or bcc - #33810

Merged
taylorotwell merged 3 commits into
laravel:7.xfrom
traubisoda:plain_cc_email_address_array
Aug 11, 2020
Merged

[7.x] Let mailables accept a simple array of email addresses as cc or bcc#33810
taylorotwell merged 3 commits into
laravel:7.xfrom
traubisoda:plain_cc_email_address_array

Conversation

@traubisoda

Copy link
Copy Markdown
Contributor

Currently we can only set a single email address, an associative array, or an object as cc or bcc in Mailables.
I think it would be nice, if it were possible just to pass a simple array of email addresses as cc/bcc. As of now, if someone has a simple array, it has to be mapped to have an email key with the address.

Example:

// This is valid
Mail::to('user@foo.com')->cc('john@doe.com')->send(new SomeMailable());

// This is valid
Mail::to('user@foo.com')->cc('john@doe.com')->send(new SomeMailable());

// This throws an exception: "Trying to get property 'email' of non-object"
Mail::to('user@foo.com')->cc(['john@doe.com', 'jane@doe.com'])->send(new SomeMailable());

// Possible workaround, me no gusta
Mail::to('user@foo.com')->cc(
  collect(['john@doe.com', 'jande@doe.com'])->map(fn ($email) => compact('email'))
)->send(new SomeMailable());

Since Mailable does not require a recipient name anywhere, and already accepts a single email address as cc/bcc, it would make sense if it accepted a simple array of addresses in my opinion.

@driesvints driesvints changed the title Let mailables accept a simple array of email addresses as cc or bcc [7.x] Let mailables accept a simple array of email addresses as cc or bcc Aug 10, 2020
@taylorotwell
taylorotwell merged commit 44c32a2 into laravel:7.x Aug 11, 2020
@traubisoda
traubisoda deleted the plain_cc_email_address_array branch August 11, 2020 13:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants