PHP code example of libreworks / swiftmailer-spools

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

    

libreworks / swiftmailer-spools example snippets


$mailer = \Swift_Mailer::newInstance(
    \Swift_SpoolTransport::newInstance(
        $spool // your spool goes here
    )
);
// this e-mail will get spooled
$mailer->send(new \Swift_Message($subject, $body, $contentType, $charset));

$transport = \Swift_SmtpTransport::newInstance($smtpHost, $smtpPort, $smtpEncrypt)
    ->setUsername($smtpUsername)
    ->setPassword($smtpPassword);

$spool->recover();
$spool->flushQueue($transport);

$pdo = new \PDO("mysql:dbname=testdb;host=127.0.0.1", 'user', 'pass');
$spool = new \Swift_PdoSpool(
    $pdo,
    "email", // table
    "id", // primary key field
    "message", // serialized email field
    "sentOn", // sent integer timestamp
);

$manager = new \MongoDB\Driver\Manager("mongodb://localhost:27017");
$rp = new \MongoDB\Driver\ReadPreference(\MongoDB\Driver\ReadPreference::RP_PRIMARY_PREFERRED);
$wr = new \MongoDB\Driver\WriteConcern(\MongoDB\Driver\WriteConcern::MAJORITY);
$spool = new \Swift_MongoDbSpool(
    $manager,
    "dbname.emails",
    $rp, // optional
    $wc, // optional
);

$client = new \MongoClient();
$db = new \MongoDB("dbname", $client);
$collection = new \MongoCollection($db, "emails");
$spool = new \Swift_MongoSpool($collection);