Closed ftrudeau closed 6 years ago
Thank you for your issue.
first: I made PR for using template id without dummy view file. and I testing now. https://github.com/s-ichikawa/laravel-sendgrid-driver/pull/79/files
If this PR merged, when using a template-id, all you need to do is set an empty array in view().
second: I will create PR for this demand in the course of this month.
Thanks to both of you!
I just started a project 2 days ago using this which needs to send the Template ID and personalization dynamic_template_data. I almost forked this, until I saw your PR. Thank you again!
Also just letting you know I pulled your dev
branch so we could get going through composer:
composer require s-ichikawa/laravel-sendgrid-driver:dev-dev
Everything worked great, your example worked awesome!
Thank you so much, can't wait to see this merge <3
In case this helps anyone, I created our own Mail wrapper so we could easily just pass in $to array
, $template_id
and $data (personalizations/dynamic_template_data)
:
public static function send($to, $template_id, $data)
{
Mail::send([], [], function (Message $message) use ($to, $template_id, $data) {
$message
->to($to)
->from(config('mail.from.address'), config('mail.from.name'))
->embedData([
'personalizations' => [
[
'dynamic_template_data' => $data,
],
],
'template_id' => $template_id,
], SendgridTransport::SMTP_API_NAME);
});
}
Also you can add after template_id a new array for unsubscribe groups.
/**
* Unsubscribe Group ID
*/
'asm' => [
'group_id' => $unsubscribe_id,
],
This is configured in SendGrid here: https://app.sendgrid.com/suppressions/advanced_suppression_manager The ID shows up in big text in the row towards the right of it.
Thanks a lot guys
In case this helps anyone, I created our own Mail wrapper so we could easily just pass in
$to array
,$template_id
and$data (personalizations/dynamic_template_data)
:public static function send($to, $template_id, $data) { Mail::send([], [], function (Message $message) use ($to, $template_id, $data) { $message ->to($to) ->from(config('mail.from.address'), config('mail.from.name')) ->embedData([ 'personalizations' => [ [ 'dynamic_template_data' => $data, ], ], 'template_id' => $template_id, ], SendgridTransport::SMTP_API_NAME); }); }
embedData method's first parameter type is array when I remove json_encode, It doesn't work.
Hello,
Thanks for this package.
I am using SendGrid templates exclusively, so I do not need views to be stores locally. If I do not pass a view to a Mailable class, I get a InvalidArgumentException. What I did is create a view with a HTML comment in it, but it feels like a hack.
Questions :
1) Any cleaner what to do this ? 2) According to Laravel's documentation, any public property defined in a Mailable will automatically be made available to the view. Would it be possible to automatically apply this to personalizations as well ?
For reference, here's some sample code I have in the build method :