Package Data | |
---|---|
Maintainer Username: | simmatrix |
Maintainer Contact: | simmatrix100@gmail.com (Wong Lai Sim) |
Package Create Date: | 2016-10-06 |
Package Last Update: | 2017-04-05 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2025-02-09 15:11:38 |
Package Statistics | |
---|---|
Total Downloads: | 712 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 17 |
Total Watchers: | 1 |
Total Forks: | 3 |
Total Open Issues: | 1 |
Sending mass mails in your Laravel applications with ease. This is a wrapper for different mail service providers.
Currently supports the sending of mass mails using Laravel's default Mail facade and Mailgun's Official SDK
It is recommended to use third party mail service such as Mailgun instead of depending on Laravel's default Mail facade because with Laravel's Mail facade, in order to protect the privacy of all subscribers, the field "BCC" is being used instead of "TO"
Add this package to your project's composer.json
file by running the following command
composer require simmatrix/laravel-mass-mailer
Add both of the service providers below to your config/app.php
file, in the providers
array.
Simmatrix\MassMailer\Providers\MassMailerServiceProvider::class,
Publish the config file and blade view template file to your application
php artisan vendor:publish --provider="Simmatrix\MassMailer\Providers\MassMailerServiceProvider"
Attributes represents the HTML elements
Retrieve the key-value pairs using the command below:
return MassMailer::getAttributes();
Here's the sample response. Each HTML element in your frontend is represented in key-value form.
{
"data": {
"ApplyTemplate": true,
"MessageContent": "",
"RecipientList": "",
"SendToAllSubscribers": false,
"SenderEmail": "noreply@nuffnang.com",
"SenderName": "Nuffnang",
"Subject": "",
"Title": "",
"Instagram": false,
}
}
The purpose of creating an attirbute to represent your HTML element is so that it can be easily parsed when it returned from your frontend application.
These are the required attributes that comes with the package by default:
To add additional fields:
php artisan make:mass-mailer-attribute YourNewFieldName
Generated file is located at app/MassMailer/Attributes/
directory
If you have some extra logic to add to your attribute, write it in the getValue()
function within your attribute file.
public function getValue()
{
// Do all necessary steps to call to Instagram API to pull the postings, then return the result
return $instagram_postings;
}
You can easily read the user's input from the attribute with:
$has_instagram = MassMailerAttribute::getUserInput( $params, 'Instagram' )
If you did Step 1(iii)
above, then you can easily get the value that you have retrieved using:
$instagram_posts = MassMailerAttribute::getInternallyPulledData( $params, 'Instagram' )
In your controller, pass in that $request
parameter into MassMailer::getParams()
, which will churn out a digestible object called MassMailerParams
that can be fed into the function MassMailer::send()
.
// YourController.php
public function send(Request $request)
{
MassMailer::send( MassMailer::getParams( $request ) );
}
If you have created your own blade view template and need to use it for the mass mail, or if you need to blast mass mails using different Mailgun domains, or to different mailing list, you can pass in the mailer options.
Currently this supports the overwriting of 3 custom mailer options, namely
presenter
: Specify the class name of the Presenter that handles your new blade template here.mailing_list
: Without this, the backend will read the data from the mailing_list
key in your app/config/mass_mailer.php
mailgun_domain
: Without this, the backend will read the data from the MAILGUN_DOMAIN
key in your .env
file// YourController.php
public function send(Request $request)
{
$mailer_options = MassMailer::createMailerOptions([
'mailing_list' => 'xxx',
'mailgun_domain' => 'xxx@xxx.com',
'presenter' => \App\MassMailer\Presenters\YourCustomPresenter::class,
]);
// Pass it to your options to the getParams()
MassMailer::send( MassMailer::getParams( $request, $mailer_options ) );
}
You need this when you want to use your own nice newsletter layout design.
This class holds all the parameters that you intended to pass them to your blade view template, and the name of the blade view template itself
To generate:
php artisan make:mass-mailer-presenter YourCustomPresenter
The console will prompt you to enter the name of your template.
resources/views/vendor/simmatrix/mass-mailer/lorem.blade.php
vendor.simmatrix.mass-mailer.lorem
app/MassMailer/Presenters/YourCustomPresenter.php
Open the file and start writing those parameters that you wish to pass to your blade view template in the setParameters()
function.
private function setParameters( MassMailerParams $params )
parent::setViewParameters([
'lorem' => 'ipsum',
'testing' => 'success'
]);
}
In your newsletter HTML layout, you can display the value in such a way:
<span>{{ $lorem }}</span>
<div>{{ $testing }}</div>
Details such as the number of bounces, clicks, complains, deliveries, drops, opens, submits, unsubscribes can be obtained by calling this method.
return MassMailer::getReport();
You may save up the draft by passing the $request
parameter into the MassMailer::saveDraft()
.
MassMailer::saveDraft( $request );
You may retrieve all of the drafts by calling this method.
return MassMailer::getDrafts();
You may retrieve individual draft by passing an ID into the method below.
return MassMailer::getDraft( $id );
You may retrieve all of the subscribers by calling this method.
return MassMailer::getSubscribers();
Thanks Chalcedonyt for the feedback given and for the useful Value Object Laravel package
MIT