Integrations

Send emails using Symfony's Mailer and MailerSend

Use the Mailer component in Symfony with MailerSend to send emails
Developer
Price

Last Updated

05/06/2023

Integration Support

See the documentation.

Additional details

MailerSend Bridge

Provides MailerSend integration for Symfony Mailer.

Installation

Symfony's Mailer & Mime components form a powerful system for creating and sending emails - complete with support for multipart messages, Twig integration, CSS inlining, file attachments, and more. Get them installed with the following:

composer require symfony/mailer-send-mailer

You'll now have a new line in your .env file that you can uncomment:

# .env
MAILER_DSN=mailersend://KEY@default

The MAILER_DSN isn't a real address: it's a convenient format that offloads most configuration work to the Mailer. The mailersend scheme activates the MailerSend component you just installed, which knows all about how to deliver messages via MailerSend. The only part you need to change is the KEY placeholder.

Each provider has different environment variables that the Mailer uses to configure the actual protocol, address, and authentication for delivery. The MailerSend component supports sending via API and SMTP. Symfony chooses the best available transport, but you can force to use one:

# .env
# force to use SMTP instead of HTTP (which is the default)
MAILER_DSN=mailersend+smtp://$MAILERSEND_SMTP_USERNAME:$MAILERSEND_SMTP_PASSWORD@default

Configuration example

# API
MAILER_DSN=mailersend+api://$MAILERSEND_API_KEY@default
# SMTP
MAILER_DSN=mailersend+smtp://$MAILERSEND_SMTP_USERNAME:$MAILERSEND_SMTP_PASSWORD@default

When using SMTP, the default timeout for sending a message before throwing an exception is the value defined in the default_socket_timeout PHP.ini option.