PHP code example of anper / mailer

1. Go to this page and download the library: Download anper/mailer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

anper / mailer example snippets


use Anper\Mailer\Transport\NullTransport;
use Anper\Mailer\Storage\MemoryStorage
use Anper\Mailer\Mailer;

$storage = new MemoryStorage([
    'hello' => [
        'subject' => 'Hello',
        'body'    => 'Hello World!',
        'from'    => '[email protected]',
        'to'      => '[email protected]',
    ],
]);

$mailer = new Mailer(new NullTransport(), $storage);

$mailer->send('hello');

// or you can modify message

$mailer->get('hello')
    ->addTo('[email protected]')
    ->send();

$context = [
    'foo' => 'bar'
];

$mailer->send('hello', $context);

// or

$message = $mailer->get('hello', $context);

use Anper\Mailer\Subscriber\Defaults;

$defaultMessageParameters = [
    'from' => '[email protected]',
    'content_type' => 'text/plain',
];

$defaultContext = [
    'teem' => 'Example Team',
];

$subscriber = new Defaults($defaultMessageParameters, $defaultContext);

$mailer->getDispatcher()
    ->addSubscriber($subscriber);