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:
- Verify your email-sending domain.
- 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 Mail Token. Follow the steps given here to generate the Send Mail Token:
- Select the Agent that you want to connect to your application.
- Navigate to SMTP/API tab. This will open the Setup Details page.
- From here you can copy your Agent specific send mail token under the API tab.
- You can either use the default Send Mail Token or generate a new one.
Agent >> SMTP/API >> Send Mail Token >> 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.
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
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