Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.3] Allow array of strings/arrays, optional name attr #15603

Merged
merged 2 commits into from
Sep 27, 2016

Conversation

misog
Copy link
Contributor

@misog misog commented Sep 26, 2016

This works in 5.3:
Mail::to('name1@example.com')->send(new OrderShipped($order));

And this works too:
$user1 = User::find(1);
$user2 = User::find(2);
Mail::to([$user1, $user2])->send(new OrderShipped($order));

However this does not work in 5.3:
Mail::to(['name1@example.com','name2@example.com'])->send(new
OrderShipped($order));

And this does not work in 5.3 too:
$user1 = User::find(1)->toArray();
$user2 = User::find(2)->toArray();
Mail::to([$user1, $user2])->send(new OrderShipped($order));

This commmit implements all cases plus it allows to not to have 'name'
attribute in User model (User models often have first_name and
last_name).

misog and others added 2 commits September 26, 2016 02:48
This works in 5.3:
Mail::to('name1@example.com')->send(new OrderShipped($order));

And this works too:
$user1 = User::find(1);
$user2 = User::find(2);
Mail::to([$user1, $user2])->send(new OrderShipped($order));

However this does not work in 5.3:
Mail::to(['name1@example.com','name2@example.com'])->send(new
OrderShipped($order));

And this does not work in 5.3 too:
$user1 = User::find(1)->toArray();
$user2 = User::find(2)->toArray();
Mail::to([$user1, $user2])->send(new OrderShipped($order));

This commmit implements all cases plus it allows to not to have 'name'
attribute in User model (User models often have first_name and
last_name).
@misog misog changed the title Allow array of strings/arrays, optional name attr [5.3] Allow array of strings/arrays, optional name attr Sep 26, 2016
@misog
Copy link
Contributor Author

misog commented Sep 26, 2016

Well, it does not work with multiple addresses - even if protected $to array in Mailable.php file contains multiple addresses, only one email is sent.

@garygreen
Copy link
Contributor

garygreen commented Sep 26, 2016

It already supports an array of addresses or collection. Also I don't think it should support [$user1->toArray(), $user2->toArray()] that's just getting silly.

@misog
Copy link
Contributor Author

misog commented Sep 26, 2016

@garygreen no, it does not currently support array of string addresses (it just crashes).
And this is not silly:

Mail::to([
    [
        'email' => 'user1@example.com',
        'name' => 'User Doe',
    ],
    [
        'email' => 'user2@example.com',
        'name' => 'User Foe',
    ],
])->send(new OrderShipped($order));

However there is some bug somewhere deeper which prevents from sending multiple emails.

@taylorotwell
Copy link
Member

Sending to multiple emails definitely works in current Laravel. I just did it.

@misog
Copy link
Contributor Author

misog commented Sep 26, 2016

This works (mailtrap.io has received):
Mail::to('test@example.com')->send(new App\Mail\OrderCreated(App\Order::first()));
=> null

This crashes:
Mail::to(['test@example.com','test2@example.com'])->send(new App\Mail\OrderCreated(App\Order::first()));

PHP error: Trying to get property of non-object in D:\xampp\htdocs\project\vendor\laravel\framework\src\Illuminate\Mail\Mailable.php on line 377
https://github.com/laravel/framework/blob/5.3/src/Illuminate/Mail/Mailable.php#L377

@taylorotwell taylorotwell merged commit 11a6b0d into laravel:5.3 Sep 27, 2016
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.

None yet

4 participants