Skip to content

Michael LaRoy - Home

Using Forms in Statamic - Sending Email with Postmark


In our last post about Statamic, we leveled-up our forms with JavaScript, using AlpinejS. Here, we think about what happens next - maybe it would be nice to be notified via email when someone submits an entry to the form on our website.

Follow along as we explore sending email with Postmark, if you’d rather just site back and relax. Watch it here:

Setting up the .env

First of all, it would be a good idea to read the docs in order to understand what is required. We are going to leverage Laravel and its pre-configured mailers to leverage Postmark to send emails for us. In our case, we are going to use an SMTP driver along with Postmark. This means, we need to configure our .env file to reflect that.

MAIL_MAILER=smtp
MAIL_HOST=smtp.postmarkapp.com
MAIL_PORT=587
MAIL_USERNAME=<your-postmark-api-token>
MAIL_PASSWORD=<your-postmark-api-token>
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="your@email.com"
MAIL_FROM_NAME="${APP_NAME}"

In order to get your api token, you will first need an account with Postmark. Once in there, you’ll have to create a “server,” which is just a container/bucket for a group of emails you want to manage. This could be a live server for a production app, or a sandbox/test server that won’t actually send the emails, but will capture them for you to see that it will actually work.

Screenshot Postmark Server

Connect your DNS

Additionally, you will need to connect your DNS to Postmark, so that it can actually send emails through your real email address, and actually be perceived as legitimate and land in an inbox, not in a spam folder.

In Postmark, this is called a Signature. When you create this, it will provide 2 separate things to add to your DNS: a TXT value, and a CNAME value. Create these wherever you manage your domain, and add the values provided by Postmark. There should be a button to press to test the connection from Postmark, which should turn green with a success message once the DNS settings have propagated, which can take some time.

Screenshot Postmark Signature

You can test the connection in Statamic under the Tools > Utilities option in the Control Panel, where it should show you your .env settings. There is also a field to input an email to send a test message, and press the button, and you should be good to go.

Connecting Your Form

Finally, we can configure our form to send an email once a submission has been made. When editing the form, select Add Email and input your Recipient address, and any other details you might want to include, like a subject line.

Screenshot Statamic form email config

Next, configure the last option there to SMTP so that it will use the details we set up in our .env above.

Screenshot Statamic form mailer config

Finally, test it out by submitting your form. You should either receive an email in your Recipient inbox, or it should be available in your sandbox right withing Postmark.

Either way, you shouldn’t need anything else to get you where you need to go.

We don't need roads - Back to the Future

Join my Email List

Get notified about my work with Statamic - from new YouTube videos to articles and tutorials on my blog, and more.