You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Aug 27, 2021. It is now read-only.
description: View instructions on how to easily send email with Laravel using SendGrid, by setting up setting up Laravel's built in mailer.
7
+
description: View instructions on how to easily send email with Laravel using SendGrid, by setting up setting up Laravel's Mailables Class.
8
8
navigation:
9
9
show: true
10
10
---
11
11
12
-
Laravel comes with an email sending library built in, so we just need to set it to use SendGrid over SMTP. Check out the docs for [Laravel's mailer](http://laravel.com/docs/mail) for details.
12
+
Laravel provides a clean API over the popular SwiftMailer library with drivers for SMTP, PHP's `mail`, `sendmail` and more. For this example, we'll be sending an email with SendGrid using the SMTP Driver. For more information, check out the docs for [Laravel's Mail interface](http://laravel.com/docs/mail).
13
13
14
-
In `app/config/mail.php` you need to configure these settings:
14
+
Laravel 5.5 LTS uses Mailable classes. Mailables in Laravel abstracts building emails with a mailable class. Mailables are responsible for collating data and passing them to views.
15
+
16
+
{% anchor h2 %}
17
+
Before you begin
18
+
{% endanchor %}
19
+
20
+
In `.env` you need to find and configure these variables:
You can use Laravel's Mail class just like you normally would, but all email will be sent through SendGrid!
86
+
In Laravel `Views` are used as 'templates' when sending an email. Let's create a file under `app/resources/views/emails/test.blade.php` and insert this code:
87
+
88
+
{% codeblock lang:html %}
89
+
<!DOCTYPE html>
90
+
<htmllang="en-US">
91
+
<head>
92
+
<metacharset="utf-8">
93
+
</head>
94
+
<body>
95
+
<h2>Test Email</h2>
96
+
<p>{{ $message }}</p>
97
+
</body>
98
+
</html>
99
+
{% endcodeblock %}
100
+
101
+
{% anchor h2 %}
102
+
Sending an email
103
+
{% endanchor %}
104
+
105
+
Now that we have our Mailable Class created, all we need to do is run this code:
Categories in sendgrid allow you to split your statistics into categories. An example would be if you have a white labeled service you can split your statistics by the user login.
120
+
Categories in SendGrid allow you to split your statistics into sections. For example, if you have a Whitelabeled service, you can split your statistics by the user login.
48
121
49
-
Another useful feature of sendgrid is the notifications. If you want to complete the feedback loop for your product you can pass identifiers as a header which relate to a record in your database which you can then parse the notifications against that record to track deliveries/opens/clicks/bounces.
122
+
Another useful tool is event notifications. If you want to complete the feedback loop for your product you can pass identifiers as a header which relate to a record in your database which you can then parse the notifications against that record to track deliveries/opens/clicks/bounces.
50
123
124
+
The `withSwiftMessage` method of the `Mailable` base class allows you to register the callback that is invoked with the raw SwiftMailer message instance before sending the message. This knowledge allows you to customize the message before delivery. To customize your message, use something similar to this:
51
125
52
126
{% codeblock lang:php %}
53
127
<?php
54
128
55
-
Mail::send('emails.view', $data, function ($message)
0 commit comments