PHP code example of byjg / mailwrapper

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

    

byjg / mailwrapper example snippets



// Create the email envelope
$envelope = new ByJG\Mail\Envelope();
$envelope->setFrom('[email protected]', 'John Doe');
$envelope->addTo('[email protected]');
$envelope->setSubject('Email Subject');
$envelope->setBody('html text body');


// Register the available class
\ByJG\Mail\MailerFactory::registerMailer(\ByJG\Mail\Wrapper\PHPMailerWrapper::class);
\ByJG\Mail\MailerFactory::registerMailer(\ByJG\Mail\Wrapper\MailgunApiWrapper::class);

// Create the proper mailer based on the scheme
// In the example below will find the "mailgun" scheme
$mailer = \ByJG\Mail\MailerFactory::create('mailgun://api:YOUR_API_KEY@YOUR_DOMAIN');

// Send the email:
$mailer->send($envelope);


$mailer = new \ByJG\Mail\Wrapper\MailgunApiWrapper(
    new \ByJG\Util\Uri(
        'mailgun://your_api_key@YOUR_DOMAIN'
    )
);

// Send the email:
$mailer->send($envelope);


$envelope = new \ByJG\Mail\Envelope('[email protected]', '[email protected]', 'Subject', 'Body');
$envelope->addAttachment('name_of_attachement', '/path/to/file', 'mime/type');
$mailer->send($envelope);


$envelope = new \ByJG\Mail\Envelope('[email protected]', '[email protected]', 'Subject');
$envelope->addEmbedImage('mycontentname', '/path/to/image', 'mime/type');
$envelope->setBody('<img src="cid:mycontentname" />');
$mailer->send($envelope);

class MyWrapper extends \ByJG\Mail\Wrapper\BaseWrapper
{
    public static function schema()
    {
        return ['mywrapper'];
    }

    public function send(Envelope $envelope)
    {
        // Do how to send the email using your library
    }

    // You can create your own validation methods.
    public function validate(Envelope $envelope)
    {
        parent::validate($envelope);
    }
}
mermaid
flowchart TD
    byjg/mailwrapper --> ext-curl
    byjg/mailwrapper --> byjg/convert
    byjg/mailwrapper --> byjg/webrequest
    byjg/mailwrapper --> aws/aws-sdk-php
    byjg/mailwrapper --> phpmailer/phpmailer