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 for details.

In app/config/mail.php you need to configure these settings:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php

return array(
  'driver' => 'smtp',
  'host' => 'smtp.sendgrid.net',
  'port' => 587,
  'from' => array('address' => 'from@example.com', 'name' => 'John Smith'),
  'encryption' => 'tls',
  'username' => 'sendgrid_username',
  'password' => 'sendgrid_password',
);

?>

You can use Laravel’s Mail class just like you normally would, but all email will be sent through SendGrid!

1
2
3
4
5
6
7
8
<?php

Mail::send('emails.demo', $data, function($message)
{
    $message->to('jane@example.com', 'Jane Doe')->subject('This is a demo!');
});

?>