Aqui está como você pode integrar o Laravel e o Mailtrap. Cole o seguinte em .env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME= //your username generated by Mailtrap
MAIL_PASSWORD= // your password generated by Mailtrap
MAIL_FROM_ADDRESS=from@example.com
MAIL_FROM_NAME=Example
criar uma classe Mailable
php artisan make:mail MailtrapExample
Modifique o modelo de mailtrap com o seguinte código
<?php
namespace AppMail;
use IlluminateBusQueueable;
use IlluminateMailMailable;
use IlluminateQueueSerializesModels;
use IlluminateContractsQueueShouldQueue;
class MailtrapExample extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->from('mail@example.com', 'Mailtrap')
->subject('Mailtrap Confirmation')
->markdown('mails.exmpl')
->with([
'name' => 'New Mailtrap User',
'link' => 'https://mailtrap.io/inboxes'
]);
}
Crie uma rota
<?php
use AppMailMailtrapExample;
use IlluminateSupportFacadesMail;
Route::get('/send-mail', function () {
Mail::to('newuser@example.com')->send(new MailtrapExample());
return 'A message has been sent to Mailtrap!';
})