Skip to content

Conversation

@ash-jc-allen
Copy link
Contributor

@ash-jc-allen ash-jc-allen commented Dec 2, 2025

Hey! This PR proposes a new integration which allows developers to send transactional emails using Mailtrap's PHP library.

The idea behind this feature is that a developer can set these values in their .env file:

MAIL_MAILER=mailtrap
MAILTRAP_API_KEY=abc123

Then the dev will be able to use Mailtrap for sending their emails.

According to their site, Mailtrap has over 150k monthly active users. So I'd like to think there are plenty of Laravel developers in there (or budding Laravel developers) who might be able to make use of this integration 😄

Installation

To use this integration, the official Mailtrap library is required (in a similar way that an extra library is required to use mailgun as the mailing driver). So it will need to be installed using Composer via the following command:

composer require railsware/mailtrap-php

You'll then just need to add your API key and switch the mail driver in the .env file like shown above.

The integration should now be set up and ready for sending transactional emails.

There are also some new config values (in config/services.php and config/mail.php) which can be set.

Sandbox email testing

One of the really cool things I like about Mailtrap (and have been using for a few years myself) is the sandbox feature which captures emails you send from your app so you can preview them, rather than sending them to the intended recipient.

Usually, I'd need to configure my .env file with the correct SMTP credentials for sandbox testing. But for with these changes, I'd just need to set the MAILTRAP_SANDBOX_ENABLED to true and the MAILTRAP_INBOX_ID to the ID of my sandbox inbox ID like so:

MAIL_MAILER=mailtrap

MAILTRAP_API_KEY=abc123
MAILTRAP_SANDBOX_ENABLED=true
MAILTRAP_INBOX_ID=123456

So I think it's pretty cool that we can toggle the sandbox testing with just a single boolean in the environment 😄

Further PRs

If this PR is merged, I'd love to make some more PRs to the application skeleton repo to add the config fields (config/mail.php and config/services.php).

I'm also more than happy to make any necessary PRs to the docs.

Testing

I wasn't sure how to write automated tests for this, sorry. But I've manually tested different scenarios to check that the emails can be sent.

You may already have a Mailtrap account yourself. But just in case you don't, I'll email you (Taylor) some API credentials that I've set up on my Mailtrap account so you can test sending emails. I thought this would be useful so you don't have to start configuring DNS records and waiting for domain approval, etc.

Hopefully, this is something which you think is useful. Please give me a shout if you'd like anything changed at all 😄

@taylorotwell
Copy link
Member

I'm not adding more third-party mailers at this time. Happy for this to live as a package though!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants