PHP code example of pralhadstha / php-mailer-gateways

1. Go to this page and download the library: Download pralhadstha/php-mailer-gateways 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/ */

    

pralhadstha / php-mailer-gateways example snippets


use Pralhadstha\Mail\Mail;

Mail::configure([
    'default' => 'sparkpost',
    'mailers' => [
        'sparkpost' => ['provider' => 'sparkpost', 'api_key' => getenv('SPARKPOST_API_KEY')],
        'ses' => ['provider' => 'ses', 'access_key' => '...', 'secret_key' => '...'],
    ],
]);

use Pralhadstha\Mail\Mail;
use Symfony\Component\Mime\Email;

$email = (new Email())
    ->from('[email protected]')
    ->to('[email protected]')
    ->subject('Hello')
    ->text('Hi there');

Mail::send($email);                 // uses the "default" mailer
Mail::send($email, mailer: 'ses');  // or a specific named mailer

// SMTP
['provider' => 'smtp', 'host' => 'smtp.example.com', 'port' => 587, 'username' => '...', 'password' => '...']

// Amazon SES (mode: api [default] | https | smtp)
['provider' => 'ses', 'access_key' => 'AKIA...', 'secret_key' => '...', 'region' => 'us-east-1']

// Mailgun (mode: api [default] | https | smtp)
['provider' => 'mailgun', 'key' => '...', 'domain' => 'mg.example.com', 'region' => 'eu']

// SparkPost (mode: api [default] | smtp)
['provider' => 'sparkpost', 'api_key' => '...', 'region' => 'eu']

// Disable sending
['provider' => 'null']

// In-memory, for tests - see "Testing your own code" below
['provider' => 'array']

Mail::configure(['default' => 'test', 'mailers' => ['test' => ['provider' => 'array']]]);

Mail::send($email);

$transport = Mail::transport(); // ArrayTransport
$transport->count();            // 1
$transport->lastMessage();      // the Email instance

use Pralhadstha\Mail\MailerFactory;

$mailer = (new MailerFactory())->create([
    'provider' => 'sparkpost',
    'api_key' => getenv('SPARKPOST_API_KEY'),
]);

$mailer->send($email);

$factory = new MailerFactory();
$factory->registerProvider('postmark', new PostmarkProvider());

Mail::configure([...], $factory);

$factory->registerFactory(new PostmarkTransportFactory());
bash
composer