For Developers By Developers

You can integrate Mailazy in minutes with your platform. Build and monitor your email solution on a trusted foundation with technical and strategic support when you need it the most.

Configure Summary emails with SMTP for Laravel

Summary emails is an important component of any email communication strategy. In order to ensure delivery of Summary emails to your customers, reply on a trusted cloud-based email provider like Mailazy as a partner in your growth journey.

Prerequisites

You need to complete these given prerequisites, you can skip the step if you have already completed.

  1. Sign up for a Mailazy account.

  2. Complete Domain Authentication.

  3. Generate the Mailazy Access Key

Integrate Mailazy with Laravel

Laravel provides a clean API over the popular SwiftMailer library with drivers for SMTP, PHP's mail, sendmail and more. For this example, we'll be sending an email with Mailazy using the SMTP Driver. For more information, check out the docs for Laravel's Mail interface.

Laravel 5.5 LTS uses Mailable classes. Mailables in Laravel abstracts building emails with a mailable class. Mailables are responsible for collating data and passing them to views.

Before you begin

Check your .env file and configure these variables:

MAIL_MAILER=smtp
# MAIL_DRIVER=smtp # for laravel < 7
MAIL_HOST=smtp.mailazy.com
MAIL_PORT=587
MAIL_USERNAME=mailazy_apikey
MAIL_PASSWORD=mailazy_secret
MAIL_ENCRYPTION=tls
MAIL_FROM_NAME="John Smith"
[email protected]

Set the MAIL_USERNAME field to "mailazy_apikey" to inform Mailazy that you're using an API key.

The MAIL_FROM_NAME field requires double quotes because there is a space in the string.

Creating a Mailable

Categories and Unique Arguments will be stored as a “Not PII” field and may be used for counting or other operations as Mailazy runs its systems. These fields generally cannot be redacted or removed. You should take care not to place PII in this field. Mailazy does not treat this data as PII, and its value may be visible to Mailazy employees, stored long-term, and may continue to be stored after you’ve left Mailazy’s platform.

Next you need to create a Mailable class, Laravel's CLI tool called Artisan makes that a simple feat. Open CLI, go to the project directory and type:

php artisan make:mail TestEmail

This command will create a new file under app/Mail/TestEmail.php and it should look something like this:

namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Contracts\Queue\ShouldQueue;
class TestEmail extends Mailable
{
  use Queueable, SerializesModels;
  public  $data;
  public  function __construct($data)
  {
    $this->data  =  $data;
  }
  public  function build()
  {
    $address  = '[email protected]';
    $subject  = 'This is a demo!';
    $name  = 'Jane Doe';
    return  $this->view('emails.test')
      ->from($address, $name)
      ->cc($address, $name)
      ->bcc($address, $name)
      ->replyTo($address, $name)
      ->subject($subject)
      ->with([ 'test_message' =>  $this->data['message'] ]);
  }
}

In Laravel Views are used as 'templates' when sending an email. Let's create a file under app/resources/views/emails/test.blade.php and insert this code:

< !DOCTYPE html>
< html lang="en-US">
< head>
< meta charset="utf-8" />
< /head>
< body>
< h2>Test Email
< p>{{ $test_message }}

< /body> < /html>

Sending an email

Now that we have our Mailable Class created, all we need to do is run this code:

use App\Mail\TestEmail;
$data  = ['message' => 'This is a test!'];
Mail::to('[email protected]')->send(new TestEmail($data));

Send Emails with Mailazy

Mailazy is a simple email service to use, yet it provides so many benefits. Mailazy is the only simple transactional email service you’ll need. And the forever free plan lets you test drive it., Mailazy's team is well-equipped to help you quickly resolve your queries and issues. Try us for free today!

Signup for Free Developer Documentation

Ready to get started?

For High-Volume custom requirements send us an email and we will come up with a detailed quote within 24 hours.

Contact Us