Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Marins's avatar

Test Mail without server?

Hello,

can I test/mock Mail locally? with no mail server

Thank you

0 likes
2 replies
AddWebContribution's avatar
Level 42

If you configured your .env for email, you can try below sample:

Route::get('/mail', function () {

   $data = array(
        'name' => "Learning Laravel",
    );

   Mail::send('welcome', $data, function ($message) {

       $message->from('FROMEMAIL_ADDRESS', 'Learning Laravel');

       $message->to('TOEMAIL_ADDRESS')->subject('Learning Laravel test email');

   });
    if (Mail::failures()) {
        print_r(Mail::failures());
    } else {
    return "Your email has been sent successfully";
    }

});

.env something like:

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=YOUR_GMAIL_ADDRESS
MAIL_PASSWORD=YOURPASSWORD
MAIL_ENCRYPTION=tls

NOTE: Replace FROMEMAIL_ADDRESS and TOEMAIL_ADDRESS with actual one

2 likes

Please or to participate in this conversation.