Skip to main content

Email

It is recommended to use a 3rd party service for sending email. They usually offer SMTP support, and great logging and analytics. Especially on a shared host, where email is locked down, and a "naughty neighbor" can quickly get the server/IP you're emailing from blacklisted. I highly recommend using a service over SMTP, because SMTP slows response times down.

These services are supported by Laravel natively;

  • Mailgun - Free, up to 10k messages/month
  • Postmark - Tell their support you were referred for a free month
  • Amazon SES - Super cheap, free if you're using EC2

SMTP Configuration

To configure SMTP, in your .env file, you need to configure the following options:

.env
MAIL_MAILER=smtp
MAIL_FROM_NAME='phpVMS No-Reply'
MAIL_FROM_ADDRESS='no-reply@phpvms.net'
MAIL_HOST=
MAIL_PORT=
MAIL_ENCRYPTION=
MAIL_USERNAME=
MAIL_PASSWORD=

For detailed settings about host, port and encryption details please check your hosting control panel (or VPS). These settings are not generic and can differ between hosting companies, even on a custom VPS these settings are local to your install (packages installed etc.) Therefore there a no generic examples for SMTP and mail settings.

Mailgun Configuration

To use Mailgun, set your .env like:

.env
MAIL_MAILER=mailgun
MAILGUN_DOMAIN='your mailgun domain'
MAILGUN_SECRET='your mailgun secret',

Postmark Configuration

To use Postmark, set your .env like:

.env
MAIL_MAILER=postmark
POSTMARK_TOKEN='your postmark token'

SES Configuration

To use SES, set your .env like:

.env
MAIL_MAILER=postmark
AWS_ACCESS_KEY_ID='key id'
AWS_SECRET_ACCESS_KEY='access key'
AWS_DEFAULT_REGION='the region if not us-east-1'

Debugging

For debugging mail, you can use the service mailtrap.io. Mail-trail will show all of the incoming and outgoing email in an inbox, so you can test registrations, accepts, etc. It will provide you Laravel-specific configuration, which looks something like:

.env
MAIL_MAILER=smtp
MAIL_FROM_NAME='phpVMS Admin'
MAIL_FROM_ADDRESS='no-reply@phpvms.net'
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_ENCRYPTION=tls
MAIL_USERNAME='as provided'
MAIL_PASSWORD='as provided'