Laravel 8 Send Mail using Mailchimp Example

Laravel 6 , Laravel , Laravel 7 , Laravel 8

Nicesnippets

19742

28-09-2020


Laravel 8 Send Mail using Mailchimp Example

Hi Guys

In this blog,I will learn you how to send mail using mailchimp in laravel 8. we will show example of laravel 8 send mail using mailchimp.do you want to integrate the mailchimp newsletter functionality to your laravel 8application? mailchimp is an email marketing service that allows us to send newsletters to our subscribers. in this article, i show you how to integrate the mailchimp newsletter into the laravel 8 website.

MailChimp is one of the popular email marketing services, which manages the subscribers of your website. Using MailChimp, your subscribers will get a newsletter about new content, announcements, deals, and much more depending on your choice. This is a kind of automated system. The website owner does not need to remember sending the newsletter to subscribers. MailChimp handles on its own, which saves us a lot of time.

Step 1: Get MailChimp API Key and Audience ID


In this setp,In order to integrate the MailChimp API, you need to get an API key and Audience ID.

Follow the steps below to get these credentials.Login to your MailChimp account. Under the user drop-down, select the Account.

Click on Extras->API keys.

Under the Your API keys section, click on Create A Key and copy your API key which we need in a moment.

Now you have your API key ready. Next, get an Audience ID to which you need to add your subscribers. For this, click on the Audience menu and then select the option Settings from the Manage Audience drop-down.

Under the Settings click on the ‘Audience name and defaults’.

On the next page, you will find your Audience ID.

Api key

Account->Extras->Api Key

Step 2:Installation Library

Mailchimp has built the fantastic library Laravel newsletter. I am going to integrate the MailChimp newsletter using this library

Open the terminal in your project’s root directory and run the command:

composer require mailchimp/mailchimp

.env

....

MAILCHIMP_APIKEY=YOUR_MAILCHIMP_API_KEY

MAILCHIMP_LIST_ID=YOUR_MAILCHIMP_LIST_ID

Step 3:Route

Make sure to replace placeholder ROUTE_HERE with the actual value.

use App\Http\Controllers\MailChimpController;

Route::get('/send-mail-using-mailchimp', [MailChimpController::class, 'index'])->name('send.mail.using.mailchimp.index');

Step 4:Controller

Next, in your controller file, add the facade of the installed package.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class MailChimpController extends Controller

{

public function index(Request $request)

{

$listId = env('MAILCHIMP_LIST_ID');

$mailchimp = new \Mailchimp(env('MAILCHIMP_KEY'));

$campaign = $mailchimp->campaigns->create('regular', [

'list_id' => $listId,

'subject' => 'Example Mail',

'from_email' => 'rajeshgajjar1997@gmail.com',

'from_name' => 'Rajesh',

'to_name' => 'Rajesh Subscribers'

], [

'html' => $request->input('content'),

'text' => strip_tags($request->input('content'))

]);

//Send campaign

$mailchimp->campaigns->send($campaign['id']);

dd('Campaign send successfully.');

}

}

It will help you...


Recommended Posts