PHP code example of drewlabs / envoyer

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

    

drewlabs / envoyer example snippets



// Create a notification class

// Mail.php

use Drewlabs\Envoyer\Contracts\AttachmentsAware;
use Drewlabs\Envoyer\Contracts\NotificationInterface;
use SplFileInfo;

/** @package Drewlabs\Notifications\Tests\Stubs */
class Mail implements NotificationInterface, AttachmentsAware
{

    public function setAttachments($attachments = [])
    {
    }

    public function getAttachments()
    {
        return [
            new SplFileInfo(__DIR__ . '/../contents/bordereau.pdf'),
        ];
    }
    public function getCc()
    {
        return null;
    }

    public function getSubject()
    {
        return "Successful registration";
    }

    public function getSender()
    {
        return new Address;
    }

    public function getReceiver()
    {
        return "[email protected]";
    }

    public function getContent()
    {
        return "<p>Hey Azandrew! Thank you for your registration</p>";
    }
}

// defines a test driver to use
DriverRegistryFacade::defineDriver('test', static function () {
    return new TestDriver();
});

// Send notification using command interface
$result = $command->driver('test')->send(new Mail);

// SendMail.php
$result = $command->driver('smtp')->send(new Mail);


// SendMessage.php
$result = $command->driver('smtp')->send(new Message);


// SendMessage.php
$result = $command->driver('smpp')->send(new Message);


use Drewlabs\Envoyer\Contracts\ClientInterface;
use Drewlabs\Envoyer\Contracts\NotificationInterface;
use Drewlabs\Envoyer\Contracts\NotificationResult;
use RuntimeException;

class TestDriver implements ClientInterface
{

    public function __construct()
    {
    }

    public function sendRequest(NotificationInterface $instance): NotificationResult
    {
        // TODO : Provide send request implementation logic
    }
}


// Start building the mail
$mail = \Drewlabs\Envoyer\Mail::new()
    ->from('...', '...')
    ->to('...')
    ->bCc('...')
    ->subject('...')
    ->attach(new SplFileInfo(__DIR__ . '/...'))
    ->content(


// Create a messageable class
$message = Messageable::new()
                        ->from('...')
                        ->to('...')
                        ->content("...");
    
// Use 

use Drewlabs\Notifications\Command;
use Drewlabs\Notifications\Drivers;

$result = Command::driver(Drivers::AWS_SES)->send(/* ... */);

use Drewlabs\Envoyer\DriverRegistryFacade;

DriverRegistryFacade::defineDriver('test', static function () {
    return new TestProvider();
});