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.

Trusted by 120+ partners and delivering over 650 Million emails/month

Configure Referrals emails with SMTP for Laravel

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


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_DRIVER=smtp # for laravel < 7

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  = '';
    $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)
      ->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('')->send(new TestEmail($data));

Send transactional emails with Mailazy

Mailazy email delivery platform is powered by AI and uses the global infrastructure so that you can scale effortlessly. Mailazy is the trusted transactional email provider for hundreds of businesses and we are growing every day. We are known for being the most reliable and trusted senders on the internet.

Ready to get started?

Get started — it's free