Skip to content
Send personalized emails to clients in easily way using real data and templates with variables.
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.github
src arrangements to 1.0.0 release, add coverage, fixed test and readme, c… May 14, 2019
tests
.gitattributes
.gitignore
.php_cs
.travis.yml
CHANGELOG.md
LICENSE arrangements to 1.0.0 release, add coverage, fixed test and readme, c… May 14, 2019
composer.json
readme.md

readme.md

personalized

Send personalized emails to clients in easily way using real data and templates with variables.

GitHub release downloads count issues count Build Status
GitHub repo size License PHP from Packagist

Overview

Personalized is a PHP library with which you can easily send e-mails to clients from data source using templates. Templates uses variables to easily replace with real data. Personalized can send mail directly from your mailbox using PHPMailer.

You can get data from:

  • CSV files
  • MySQL Database

Requirements

  • PHP >= 7.0

Installation

$ composer require plumthedev/personalized

Templates

Templates is a HTML documents with variables which allows to personalize mail message for recipient.

<h1>Hello %{name}</h1>

personalized easily supports personalize mails.

<?php
    $personalized = new Personalized($config);
    
    $personalized->data->each(function($client) use ($personalized) {
        echo $personalized->template->personalize($client);
    });

Variables are wrapped in %{} and their names come from the data source tables titles.

Data

Data can be provided from CSV files and MySQL databases. You can easily manage provided data like filtering, getting by row or loop.

<?php
    $personalized = new Personalized($config);
    
    $scoreBigEnough = $p->data->filter(function($client){
        return $client['score'] > 10;
    });

Data is a class which contains some useful methods to manage data.

Mail

You can sends mail using PHPMailer which is the best mail support PHP library. Can it be better?

<?php
    $personalized = new Personalized($config);
    
    $personalized->data->each(function($client) use ($personalized) {
        // now personalize template and save result to variable
        $personalizedMailTemplate = $personalized->template->personalize($client);
        
        // set body of message and add recipient
        $personalized->mail->setBody($personalizedMailTemplate);
        $personalized->mail->addAddress($client['email'], $client['name']);
        
        // send mail!
        $personalized->mail->send();            
    });

A Simple Example

<?php
    require_once __DIR__ . '/vendor/autoload.php';
    use personalized\Personalized;
    
    $config = [
          'data' => [
                  'source' => 'mysql',
                  'db' => [
                      'host' => '127.0.0.1',
                      'user' => 'databaseUser',
                      'pass' => 'databasePassword',
                      'name' => 'mailing',
                      'statement' => [
                          'query' => 'SELECT * FROM clients',
                      ],
                  ],
          ],
          'template' => [
              'path' => __DIR__ . '/mailing/templates/welcome.html',
              'duplicates' => [
                  'path' => __DIR__ . '/mailing/templates/duplicates',
              ],
          ],
          'mail' => [
              'server' => [
                  'host' => 'smtp1.example.com;smtp2.example.com',
                  'username' => 'user@example.com',
                  'password' => 'secret',
              ],
              'message' => [
                  'subject' => 'My super product for you!',
              ],
              'from' => [
                  'address' => 'contact@kacperpruszynski.pl',
                  'name' => 'Kacper Pruszynski',
              ],
          ],
    ];
    
    $personalized = new Personalized($config);
    
    $personalized->data->each(function($client) use ($personalized) {
        $personalizedMailTemplate = $personalized->template->personalize($client);
        
        $personalized->mail->setBody($personalizedMailTemplate);
        $personalized->mail->addAddress($client['email'], $client['name']);
        
        $personalized->mail->send();            
    });

Credits & Contributing

Personalized is open source so if you want to contribute, you can.

Please submit bug reports, suggestions and pull requests to the GitHub issue tracker.

I want to thanks:

  • supergrecko - Thanks you for excellent feedback about system requirements and support with this!

License

MIT

You can’t perform that action at this time.