PHP code example of massimo-filippi / mail-module

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

    

massimo-filippi / mail-module example snippets




/**
 * List of enabled modules for this application.
 *
 * This should be an array of module namespaces used in the application.
 */
return [
    'Zend\Mail',
    'Zend\Router',
    'Zend\Validator',
    'MassimoFilippi\MailModule', // Add this line, ideally before Application module.
    'Application',
];



return [
    // Config array for modules in MassimoFilippi namespace (our modules).
    'massimo_filippi' => [
        
        // Config array for MailModule.
        'mail_module' => [
            
            // Adapter you want to use.
            'adapter' => \MassimoFilippi\MailModule\Adapter\Mailjet\MailjetAdapter::class,
            
            // Adapter's parameters needed to create adapter's instance (e.g., api key or password).
            'adapter_params' => [
                'api_key' => '---API-KEY---',
                'api_secret' => '---API-SECRET---',
                'sandbox_mode' => false, // will not send email if true, but API will response
            ],
        ],
    ],
];



return [
    // Config array for modules in MassimoFilippi namespace (our modules).
    'massimo_filippi' => [
        
        // Config array for MailModule.
        'mail_module' => [
            
            // Adapter you want to use.
            'adapter' => \MassimoFilippi\MailModule\Adapter\SparkPost\SparkPostAdapter::class,
            
            // Adapter's parameters needed to create adapter's instance (e.g., api key or password).
            'adapter_params' => [
                'api_key' => '---API-KEY---',
            ],
        ],
    ],
];



return [
    // Config array for modules in MassimoFilippi namespace (our modules).
    'massimo_filippi' => [
        
        // Config array for MailModule.
        'mail_module' => [
            
            // Adapter you want to use.
            'adapter' => \MassimoFilippi\MailModule\Adapter\SparkPost\SparkPostSmtpAdapter::class,
            
            // Adapter's parameters needed to create adapter's instance (e.g., api key or password).
            'adapter_params' => [
                'api_key' => '---SMTP-API-KEY---',
            ],
        ],
    ],
];

 

use MassimoFilippi\MailModule\Model\Message\Message;
use MassimoFilippi\MailModule\Model\Recipient\Recipient;
use MassimoFilippi\MailModule\Model\Sender\Sender;

try {   
    // Remember that some services need sender's email address enabled first!
    $sender = new Sender('[email protected]', 'Example.com');
     
    $recipient = new Recipient('[email protected]');
    $recipient->setName('John Doe');
     
    $message = new Message($sender, $recipient);
     
    $message->setSubject('Test');
     
    $message->setMessage('Hello World!');
     
    $this->mailService->sendMail($message);
} catch (\Exception $exception) {
    var_dump($exception->getMessage());
}