Configuring Laravel to use Mailgun is easy. We only need an account at mailgun.com and, for testing, some authorized recipient email addresses.
Contents
Laravel Configuration
We have the following mail configuration in the .env file.
These values are available in your mailgun account.
For example:
Authorized Recipients
For testing, we are using a sandbox domain and email recipients have to authorize your account to send them emails.
Sample Codes
PHP Codes
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 |
<?php use Illuminate\Support\Facades\Mail; Route::get('/', function () { $data = [ 'title' => 'Test email', 'content' => 'content' ]; Mail::send('emails.test', $data, function($message) { $message->to('sangabriel.karl@xxx.com', 'karl')->subject('hello how are you?'); }); }); |
View
[wp_ad_camp_4]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>Page Title</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" type="text/css" media="screen" href="main.css" /> <script src="main.js"></script> </head> <body> <h1>{{$title}}</h1> <p>{{$content}} </body> </html> |
Sample Email Received
Email received
Email Details