Applications built using the Laravel framework can now integrate with ZeptoMail to send transactional emails. This guide will show you how to do that.

Pre-requisites

Before you connect with Laravel, ensure you have the following in place:

  1. Verify your email-sending domain.
  2. Generate the API key.

Installation

Install ZeptoMail for Laravel using the Composer package manager. Navigate to your Laravel application's terminal and paste the following

Configuration

To send emails using ZeptoMail, set it as a mail driver. Create a new mailer definition in the mailers array of your application's configuration file.

composer require zohomail/laravel-zeptomail:dev-main

Navigate to your application's .env file and add the Send API key. Follow the steps given here to generate the Send API key:

  1. Select the Agent that you want to connect to your application.
  2. Navigate to SMTP/API tab. This will open the Setup Details page.
  3. From here you can copy your Agent specific Send API key under the API tab.
  4. You can either use the default Send API key or generate a new one.

Agent >> SMTP/API >> Send API key >> Click to copy icon.

'zeptomail' => [ 'transport' => 'zeptomail', ],

Once you configure ZeptoMail, you can check the configuration by sending a test email.

Test email

  • Open your command prompt and launch the tinker environment
ZEPTOMAIL_HOST=zoho.com
		ZEPTOMAIL_TOKEN="SEND_MAIL_TOKEN"
		MAIL_MAILER=zeptomail
		MAIL_FROM_ADDRESS=invoice@zylker.com
		MAIL_FROM_NAME="App Name"
Next, execute the following email-sending command

php artisan tinker

  • Enter the relevant email address in the to field.
  • Navigate to your application terminal and execute the command. 

Mail::raw('This is a test email', function ($message) { $message->to('test@email.com') ->subject('Testing Laravel'); });

Once you test your configuration, you can automate your transactional email-sending in your application using Laravel. Follow the steps below to do so.

Setup email-sending

  • First, create a mailable class.
  • Next, you should configure the app/Mail/Welcomemail.php class using the code given below

php artisan make:mail Welcomemail

  • Next, create a custom template under resources/views/mail/welcome-email.blade.php. 

		?php namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Attachment;
use Illuminate\Mail\Mailable;
use Illuminate\Mail\Mailables\Address;
use Illuminate\Mail\Mailables\Content;
use Illuminate\Mail\Mailables\Envelope;
use Illuminate\Mail\Mailables\Headers;
use Illuminate\Queue\SerializesModels;
use Zeptomail\EmailHeader\CategoryHeader;
use Zeptomail\EmailHeader\CustomVariableHeader;
use Symfony\Component\Mime\Email;
use Symfony\Component\Mime\Header\UnstructuredHeader;
class ZeptoWelcomeMail extends Mailable
{ use Queueable, SerializesModels; private string $name; /** * Create a new message instance. */ public function __construct(string $name) { $this-?>name
		= $name; } /** * Get the message envelope. */ public function envelope(): Envelope { return new Envelope( from:
		new Address('rebecca@zylker.com', 'Rebecca'),//sender address should be verified replyTo: [ new
		Address('taylor@zylkertech.com', 'Taylor'), ], subject: 'Welcome Mail' ); } /** * Get the message content
		definition. */ public function content(): Content { return new Content( view: 'mail.zepto-welcome-email', with:
		['name' => $this->name], ); }
		}
	
  • Next, paste the following router code to the app/routes/console.php file. 

Hi {{$name}},

Welcome to the service!

  • Finally, you can check your configuration by sending an email. Navigate to your console and paste the following command
?php use App\Mail\ZeptoWelcomeMail;
use Illuminate\Support\Facades\Mail;
Artisan::command('send-zepto-welcome-mail', function () { Mail::to('rebecca@zylker.com')-?>send(new
		ZeptoWelcomeMail("Jon"));
		})->purpose('Send welcome mail');
	

Note:

Before you get started it is important to know that ZeptoMail is for sending transactional emails like welcome emailers, password resets emails, OTPs. We do not support sending of bulk emails or promotional emails like newsletters or marketing campaign emails. If you are looking for a bulk email provider, you can visit Zoho Campaigns.

php artisan send-zepto-welcome-mail

PREVIOUS

UP NEXT