PHP code example of finesse / swiftmailer-defaults-plugin

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

    

finesse / swiftmailer-defaults-plugin example snippets


// Set up a Mailer
$transport = new Swift_SmtpTransport();
$mailer = new Swift_Mailer($transport);
$mailer->registerPlugin(new Finesse\SwiftMailerDefaultsPlugin\SwiftMailerDefaultsPlugin([
    'from' => ['[email protected]' => 'John Doe'],
    'replyTo' => '[email protected]'
]));

// Use the Mailer many times
$mailer->send(
    (new Swift_Message())
        ->setTo('[email protected]', 'Bill Johnson')
        ->setSubject('Hi')
        ->setBody('This is awesome, I don\'t need to specify the from address!')
);

use Finesse\SwiftMailerDefaultsPlugin\SwiftMailerDefaultsPlugin;
use Swift_Mailer;
use Swift_SmtpTransport;

// Setup an emails sending transport
$transport = new Swift_SmtpTransport();

// Create a plugin instance
$defaultsPlugin = new SwiftMailerDefaultsPlugin(/* default properties */);

// Assemble them with a mailer
$mailer = new Swift_Mailer($transport);
$mailer->registerPlugin($defaultsPlugin);

use Swift_Message;

$message = new Swift_Message();
$mailer->send($message);

$defaultsPlugin = new SwiftMailerDefaultsPlugin([
    'from' => '[email protected]',
    'subject' => 'Notification'
]);

$defaultsPlugin->setDefault('sender', '[email protected]', 'Chasy');

$defaultsPlugin->unsetDefault('sender');