PHP code example of codememory / mailer

1. Go to this page and download the library: Download codememory/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/ */

    

codememory / mailer example snippets




use Codememory\Components\Mail\Workers\ServerWorker;
use Codememory\Components\Mail\Interfaces\ServerConfigurationInterface;

{
        $configuration
            ->setHost('smtp.gmail.com')
            ->setPort(487)
            ->setMimeTypeBody('text/html')
            ->setCharset('utf8');
    });



use Codememory\Components\Mail\Workers\UserWorker;
use Codememory\Components\Mail\Interfaces\UserConfigurationInterface;


        $configuration
            ->setUsername('[email protected]')
            ->setPassword('user password')
            ->setServer($serverWorker->getServer('server-name')) // Сервер, добавленный ранее
            ->addFrom('[email protected]', 'Example')
    });



use Codememory\Components\Mail\Mailer;
use Codememory\Components\Mail\Interfaces\MessageInterface;

// В качестве параметра, передать добавленного пользователя
$mailer = new Mailer($userWorker->getUser('user-alias'));

$mailer
    ->createMessage(function (MessageInterface $message) {
        $message
            ->setSubject('Тема #1')
            ->setBody('Контент темы #1')
            ->addRecipientAddress('email', 'user<необязательно>')
            ->attach('images/image.png');
    })
    ->createMessage(function (MessageInterface $message) {
        $message
            ->setSubject('Тема #2')
            ->setBody('Контент темы #2')
            ->addRecipientAddress('email');
    });

// Отправляем все созданные сообщения
$mailer->send();



use Codememory\Components\Mail\MailerPack;

Worker);

$mailer = $mailerPack->getMailer(); // Returned: Codememory\Components\Mail\Mailer