PHP code example of charcoal / email

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

    

charcoal / email example snippets


use Charcoal\Email\ServiceProvider\EmailServiceProvider;
use Pimple\Container;

$container = new Container();
$container->register(new EmailServiceProvider());

$email = $container['email'];
$email->setData([
    'from' => '"Company inc." <[email protected]>',
    'bcc'  => '[email protected]',
    'to'   => [
        '[email protected]',
        '"Some guy" <[email protected]>',
        [
            'name'  => 'Other guy',
            'email' => '[email protected]',
        ],
    ],
    'reply_to' => [
        'name'  => 'Jack CEO',
        'email' => '[email protected]'
    ],
    'subject'        => $this->translator->trans('Email subject'),
    'campaign'       => 'Campaign identifier',
    'template_ident' => 'foo/email/default-email'
    'attachments'    => [
        'foo/bar.pdf',
        'foo/baz.pdf',
    ],
]);

// Dispatch immediately:
$email->send();

// Alternately, dispatch at a later date using the queue system:
$email->queue('in 5 minutes');