PHP code example of phpro / zf-mail-manager

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

    

phpro / zf-mail-manager example snippets



return array(
    'modules' => array(
        'Phpro\MailManager',
        // other libs...
    ),
    // Other config
);


return array(
    //
    // Define a Default Mailmanager
    //
    'service_manager' => array(
        'aliases' => array(
            'Phpro\MailManager\DefaultAdapter' => 'Phpro\MailManager\Adapter\ZendMailAdapter',
        )
    ),

    //
    // Paths to e-mail templates for renderable e-mail objects.
    //
    'view_manager' => [
        'template_map' => [
            'mails/layout' => __DIR__ . '/../view/mails/layout.phtml',
            'mails/customer/registered' => __DIR__ . '/../view/mails/customer/registered.phtml',
        ],
    ],

    //
    // Custom e-mail plugin manager
    //
    'mail_manager' => [
        'invokables' => [
            'CustomerRegisteredMail' => 'CustomerRegisteredMail',
        ],
    ],
);


use MailManager\Mail\Base\ZendMail;

/**
 * Class ShareCollection
 *
 * @package MailManager\Mail
 */
class CustomerRegisteredMail extends ZendMail
{
    protected $viewFile = 'mails/customer/registered';
    protected $subject = 'Customer Registered';
    protected $to = ['[email protected]' => 'Me'];
    protected $from = ['[email protected]' => 'Me'];

    // Custom view parameters
    protected $params = [
        'name' => 'Me',
        'email' => '[email protected]',
    ];

    // Other settings like headers, attachments, ...
}


// Through the mail plugin manager:
$mailManager = $serviceManager->get('Phpro\MailManager');
$mail = $mailManager->get('CustomerRegisteredMail');
$mailManager->send($mail);

// Without the mail plugin manager:
$mailManager = $serviceManager->get('Phpro\MailManager');
$mail = new CustomerRegisteredMail();
$mailManager->send($mail);

curl -s https://getcomposer.org/installer | php
php composer.phar install