2017 © Pedro Peláez
 

library simple-mail

A quick and simple method to send emails

image

kisphp/simple-mail

A quick and simple method to send emails

  • Tuesday, August 30, 2016
  • by kisphp
  • Repository
  • 2 Watchers
  • 0 Stars
  • 135 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 4 Versions
  • 65 % Grown

The README.md

Kisphp Simple mailer

Build Status codecov.io, (*1)

Latest Stable Version Total Downloads License Monthly Downloads, (*2)

Quick send emails with swift mailer for your website with a very simple implementation. By default is configured to send through google., (*3)

Installation

composer require kisphp/simple-mail

Configuration

If you already use composer into your project, then the required libraries will be automatically included. Other way you'll have to include autoloader into your php file:, (*4)

require_once '/path/to/vendor/autoload.php';

First step you need to do, is to create a Configuration class that will implement Kisphp\Mail\MailConfigInterface;., (*5)

<?php

namespace Demo;

use Kisphp\Mail\MailConfigInterface;

class DemoMailConfig implements MailConfigInterface
{
    public function getHost()
    {
        return 'ssl://smtp.gmail.com';
    }

    public function getPort()
    {
        return 465;
    }

    public function getSenderUsername()
    {
        return 'your-email-address@gmail.com';
    }

    public function getSenderPassword()
    {
        return 'your account password';
    }

    public function getMailEncryptionType()
    {
        return null;
    }

    public function getFromEmail()
    {
        return 'no-reply@example.com';
    }

    public function getFromName()
    {
        return 'My website';
    }
}

Next you'll need to create extend AbstractMailerFactory class to use your configuration:, (*6)

class DemoMailerFactory extends AbstractMailerFactory
{
    /**
     * @return DemoMailConfig
     */
    public function createMailConfig()
    {
        return new DemoMailConfig();
    }
}

And from here you can start to use it:, (*7)

<?php

$messenger = DemoMailerFactory::createMailer();

// recipients
$recipients = [
    'user_1@example.com' => 'User name 1',
    'user_2@example.com' => 'User name 2',
];

$subject = 'Testing mail';
$htmlMessage = 'this is my <b>message</b> for you';

// compose email
$messenger->createMailMessage($recipients, $subject, $htmlMessage);

// send the email and get the number of how many emails were sent
$emailsSent = $messenger->send();

Change mail transport type

To change the transport type you'll have to extend the createMailTransport method from Messenger class:, (*8)

<?php

use Kisphp\Mail\Messenger;

class ProjectMessenger extends Messenger
{
    /**
     * @return $this
     */
    protected function createMailTransport()
    {
        $this->transport = \Swift_MailTransport::newInstance();

        return $this;
    }
}

class DemoMailerFactory extends AbstractMailerFactory
{

    // createMailConfig method here

    /**
     * @param MailConfigInterface $config
     *
     * @return MessengerInterface
     */
    public function createMessenger(MailConfigInterface $config)
    {
        return new ProjectMessenger($config);
    }
}

// and load this class in your project
$messenger = new ProjectMessenger($config);

More details can be seen here: SwiftMailer Sending, (*9)

The Versions

30/08 2016

dev-master

9999999-dev

A quick and simple method to send emails

  Sources   Download

MIT

The Requires

 

The Development Requires

mail message kisphp simple mail

30/08 2016

2.0.0

2.0.0.0

A quick and simple method to send emails

  Sources   Download

MIT

The Requires

 

The Development Requires

mail message kisphp simple mail

15/04 2016

1.0.1

1.0.1.0

A quick and simple method to send emails

  Sources   Download

MIT

The Requires

 

The Development Requires

mail message kisphp simple mail

12/03 2016

1.0.0

1.0.0.0

A quick and simple method to send emails

  Sources   Download

MIT

The Requires

 

The Development Requires

mail message kisphp simple mail