Git Product home page Git Product logo

super-mailer's Introduction

Super Mailer

A convenient package for sending mass html emails.

What does it do?

Instead of writing your own scripts to send emails, you can quickly configure the package with your SMTP details, create your message body and subject templates, send the email and be done with it! It's that simple!

Installation

Clone the repository and use composer to install the dependencies.

composer install

Then include vendor/autoload.php in your PHP file to start using the Masnun\SuperMailer\SuperMailer class.

Usage

The Masnun\SuperMailer\SuperMailer class constructor has the following paramters:

  • SMTP Host
  • SMTP Port
  • SMTP Username
  • SMTP Password
  • Subject Template (String)
  • Path to message body template file
  • Your Name
  • Your Email address

Your name and email address is used as the "From" header of the email.

The object instance has a method sendEmail that we use to send the emails to our recipients. The method takes these arguments:

  • Name of the recipient
  • Email address of the recipient
  • The array of data that will be passed to the body and subject templates

Code Sample

<?php
// File: config.php

$smtp = [
    'host' => 'smtp.mandrillapp.com',
    'port' => 587,
    'username' => '[email protected]',
    'password' => 't4VTk0BdNPC7I9-GRY'
];
<?php
// File: index.php

require_once 'vendor/autoload.php';
require_once 'config.php';

use Masnun\SuperMailer\SuperMailer;

$mailer = new SuperMailer(
    // smtp data
    $smtp['host'],
    $smtp['port'],
    $smtp['username'],
    $smtp['password'],

    // Subject template
    'Hello {{name}}!',

    // Message body template
    'invitation.html.twig',

    //Sender details
    "Abu Ashraf Masnun",
    "[email protected]"
);


$sampleUsersArray = [

    [
        'name' => "Masnun",
        'email' => '[email protected]',
        'token' => '2eff42576ee8fc0dccdd38c0108fe8af'
    ],

    [
        'name' => 'The Doctor',
        'email' => '[email protected]',
        'token' => '2aa5a1d13d655a57dbc0e40b5b50365c'
    ]
];


foreach ($sampleUsersArray as $user)
{
    $mailer->sendEmail($user['name'], $user['email'], $user);
}

And here's the template:

Hello {{ name }}, <br/><br/>

Welcome to our super cool event of the year! Your email address is: {{ email }}
and your token is {{ token }}. <br/><br/>

-- Organizers

super-mailer's People

Contributors

masnun avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.