PHP code example of phpsoftbox / mailer

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

    

phpsoftbox / mailer example snippets


use PhpSoftBox\Mailer\Smtp\SmtpClient;
use PhpSoftBox\Mailer\Smtp\SmtpClientConfig;
use PhpSoftBox\Mailer\Transport\SmtpEmailTransport;
use PhpSoftBox\Mailer\Transport\FileEmailTransport;
use PhpSoftBox\Notifications\Email\EmailChannel;

$config = new SmtpClientConfig(
    host: 'mailhog',
    port: 1025,
    username: null,
    password: null,
    encryption: 'none',
    helo: 'domain.local',
);

$transport = new SmtpEmailTransport(
    new SmtpClient($config),
    defaultFrom: '[email protected]',
    defaultFromName: 'CHGS WMS',
);
$channel = new EmailChannel($transport, /* markdown */ null, /* renderer */ null, 'CHGS WMS <[email protected]>');

$transport = new FileEmailTransport(
    __DIR__ . '/var/mails',
    defaultFrom: '[email protected]',
    defaultFromName: 'CHGS WMS',
);

use PhpSoftBox\Mailer\Message\EmailMessage;

$message = EmailMessage::create('Тема письма')
    ->template('email/content.phtml', ['name' => 'User'])
    ->layout('email/layout.phtml', ['title' => 'Тема письма']);