PHP code example of metarush / email-fallback

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

    

metarush / email-fallback example snippets




use MetaRush\EmailFallback;

$servers = [
    0 => (new EmailFallback\Server)
        ->setHost('host1')
        ->setUser('user1')
        ->setPass('pass2')
        ->setPort(25)
        ->setEncr('TLS'),
    1 => (new EmailFallback\Server)
        ->setHost('host2')
        ->setUser('user2')
        ->setPass('pass2')
        ->setPort(25)
        ->setEncr('TLS')
];

$mailer = (new EmailFallback\Builder)
    ->setServers($servers) // array of Server objects
    ->setFromEmail(string) // "From" email
    ->setTos(array) // array of "To" email
    ->setSubject(string) // email subject
    ->setBody(string) // email body
    ->setFromName(string) // optional: "From Name"
    ->setCcs(array) // optional: array of "CC" emails
    ->setBccs(array) // optional: array of "BCC" emails
    ->setReplyTos(array) // optional: array of "Reply to" emails
    ->setAttachments(array) // optional: array of files already on the server
    ->setDebugLevel(int) // optional: PHPMailer debug level from 0 - 4. Default: 0
    ->setAdminEmails(array) // optional: array of emails that will be notified if fallback occurs
    ->setNotificationFromEmail(string) // if you set an admin email, you must set a "from" email for notifications
    ->setAppName(string) // optional: app name used on notifications
    ->setCustomHeaders(array) // optional: set/add custom headers
    ->build();

$mailer->sendEmailFallback();

$mailer->sendEmailFallback(1); // send using server with key 1

$driver = 'files';
$driverConfig = [
    'path' => '/var/www/example/emailFallbackCache/'
];

$driver = 'memcached';
$driverConfig = [
    'host'         => '127.0.0.1',
    'port'         => 11211,
    'saslUser'     => '',
    'saslPassword' => ''
];

$driver = 'redis';
$driverConfig = [
    'host'      => '127.0.0.1',
    'port'      => 6379,
    'password'  => '',
    'database'  => 0
];

->setRoundRobinMode(true)
->setRoundRobinDriver($driver)
->setRoundRobinDriverConfig($driverConfig)