How to send transactional emails with Laravel PHP framework

In this post, we’ll go over two ways you can send Laravel transactional emails via Postmark. We’ll explore the nuts and bolts of setting up the Postmark adapter for Laravel written by Craig Paul, and we’ll also look at how you can send email via SMTP. But first, let’s walk through signing up for a free Postmark developer account.

If you already have a Postmark account, you can skip this step. If you don’t have an account, head to the homepage and click “Start Free Trial” in the top right corner. Fill out your account details then click “Let’s get started.”

Postmark account creation page.

It’s worth noting that Postmark is an email service that is intended for transactional email only. Marketing campaigns and newsletters cannot be sent through Postmark.

Once you’ve entered your account information, you’ll be asked to create and confirm a sender signature. This step is necessary to send email from Postmark.

Note: Postmark developer accounts are limited to 100 emails per month. Before you can send more than that, you’ll need to go through the account approval process. To maintain high deliverability rates, Postmark is selective about the types of emails that can be sent.

Add POSTMARK_SECRET=<YOUR-SERVER-KEY-HERE> to the bottom of the file and be sure to replace <YOUR-SERVER-KEY-HERE> with your server API token, which you can find in your Postmark dashboard in the Credentials section.

Server API tokens are found on the Postmark Credentials page.

That’s it!

Now whenever you send email through your Laravel app, it will be sent via your Postmark account.

Note: If you’re running an older version of Laravel, you can check out and use an older branch of this adapter:

Now let’s look at what it takes to send email via SMTP through Postmark instead of through the Postmark API.

1. Log into your Postmark dashboard, and head to the SMTP tab within the “Setup Instructions” section:

SMTP section within the Postmark dashboard.

2. Next, open up config/mail.php in your favorite text editor.

Change the MAIL_HOST to smtp.postmarkapp.com.

Change the global from name and address to match the sender signature you set up during the Postmark account creation process above. If you have an existing Postmark account and skipped the account creation step above, you can find your sender signature by clicking “Sender Signatures” from your Postmark dashboard.

Finally, change the MAIL_USERNAME and MAIL_PASSWORD to match the username and password listed in your setup instructions:

A couple of notes:

Yes, the username and password are intentionally the same. 😉

You can ignore the sendmail driver path as this sends through SMTP, not sendmail.

Additional ports and authentication protocols are listed in your setup instructions (in the black box above), but if you don’t know what you’re doing, it’s best to leave them defaulted to port 587, and tls for the protocol.