2017 © Pedro Peláez
 

library php-laravel-mailer

php-laravel-mailer

image

elhajouji5/php-laravel-mailer

php-laravel-mailer

  • Friday, March 23, 2018
  • by elhajouji5@gmail.com
  • Repository
  • 0 Watchers
  • 0 Stars
  • 4 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

PHP/Laravel Mailer

This package allows sending email to a list of contacts based on queue/job Laravel built-in APIs, it inculdes the following options:, (*1)

Send to a list of contact
Wait a delay between sending each email
Send email notification when sending has started/finished

Guide

  • Requirements
    • PHP >= 7.1
    • Laravel >= 5.5
    • Redis
    • SMTP or API to send email through
    • Laravel/horizon
    • A connected database to your project

Installation & configuration

type the following commands respecting the same order as bellow:
, (*2)

composer require laravel/horizon
composer require elhajouji5/php-laravel-mailer
php artisan vendor:publish

type the number between brackets that matches Devinweb\phpLaravelMailer\MailerServiceProvider and hit enter
E.g:
, (*3)

  [1 ] Provider: Devinweb\phpLaravelMailer\MailerServiceProvider

and again, (*4)

php artisan vendor:publish

type the number between brackets that matches Laravel\Horizon\HorizonServiceProvider hit enter
Then, (*5)

php artisan migrate

Make sure the 3 tables failed_jobs, jobs and subscribers have migrated

, (*6)

Feeding database (Optional)

Add contacts to subscribers table (People you want to send them emails in the future)
This is the schema of subscribers table:
, (*7)

    +------------+------------------+------+-----+---------+----------------+
    | Field      | Type             | Null | Key | Default | Extra          |
    +------------+------------------+------+-----+---------+----------------+
    | id         | int(10) unsigned | NO   | PRI | NULL    | auto_increment |
    | name       | varchar(255)     | NO   |     | NULL    |                |
    | email      | varchar(255)     | NO   | UNI | NULL    |                |
    | created_at | timestamp        | YES  |     | NULL    |                |
    | updated_at | timestamp        | YES  |     | NULL    |                |
    +------------+------------------+------+-----+---------+----------------+

You can feed (insert records) your subscribers table as explained bellow:
Concerning ORM standard
use this namespace whereever you want it inside your controllers:, (*8)

    use Elhajouji5\phpLaravelMailer\Models\Subscriber;

Fill the table in the regular way, (*9)

$subscriber        = new Subscriber();
$subscriber->name  = "Somestring here";
$subscriber->email = "someemail@example.ext";
$subscriber->save();

// Or 

Subscriber::create([
    "name"  => "Somestring here",
    "email" => "someemail@example.ext",
]);

Browse and manage (edit, delete ... ) your subscribers, (*10)

// browse all
$subscribers = Subscriber::latest()->get();

// Find by $id
$subscriberX        = Subscriber::find($id);
$subscriberX->delete();

// Total number of subscribers
$numberOfSubscribers = Subscriber::count();

..
..
..

// Or without including the namespace 

$subscribers = \DB::select("SELECT * FROM subscribers");
var_dump($subscribers);

Output:, (*11)

    array:2 [
        0 => {
            "id": 3
            "name": "Somestring here"
            "email": "someemail1@example.ext"
            "created_at": "2018-03-23 14:11:07"
            "updated_at": "2018-03-23 14:11:07"
        }
        1 => {
            "id": 4
            "name": "Somestring here"
            "email": "someemail2@example.ext"
            "created_at": "2018-03-23 14:11:25"
            "updated_at": "2018-03-23 14:11:25"
        }
        ...
        ...
        ...
    ]



, (*12)

Setting up the local machine

  • Make this changes to .env file, (*13)

    - QUEUE_DRIVER=redis

    Your Redis server credentials(Below are the default credentials), (*14)

    - REDIS_HOST=127.0.0.1
    - REDIS_PASSWORD=null
    - REDIS_PORT=6379

    Your SMTP credentials(Example), (*15)

    - MAIL_DRIVER=smtp
    - MAIL_HOST=smtp.mailtrap.io
    - MAIL_PORT=2525
    - MAIL_USERNAME=null
    - MAIL_PASSWORD=null
    - MAIL_ENCRYPTION=null

How to use it

now your new service supposed to be set up and ready to use
you can try it by sending a get request to the following route:
, (*16)

[host]/send/{delay}/{sender name}/{sender email address}/{tag}

host: your domain
delay: seconds to wait between sending each email
sender name: the from name will appear in the header of the email
sender email address the email address will appear in the header of the email
tag: a simple string to distinguish your campaigns
, (*17)

Example:, (*18)

http://dev.something.local/send/10/RESAL/serviceclient@resal.me/holiday

Once you've sent the request, run this command at the root of your project, (*19)

php artisan horizon
````

You can watch the process of that job from this link

[host]/horizon
``` E.g: http://dev.something.local/horizon, (*20)

For a deeper understanding of horizon package visit this link , (*21)




, (*22)

Please feel free to share your opinion to improve this service ...

The Versions

23/03 2018

dev-master

9999999-dev

php-laravel-mailer

  Sources   Download

MIT

The Requires

 

by Elhajouji