PHP code example of messagex / email-php-sdk

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

    

messagex / email-php-sdk example snippets




use MessageX\Service\Email\ValueObject\Email;
use MessageX\Service\Email\ValueObject\Body\Body;
use MessageX\Service\Email\EmailClient;

$emailClient = new EmailClient([
        'credentials' => ['key' => 'XXXXX', 'secret' => 'XXXXX']
    ]);

$emailClient->sendEmail(
    (new Email('John Doe <[email protected]>', ['Jane Doe <[email protected]>']))
        ->setSubject('Greetings')
        ->addBody(new Body('text/plain', 'Hi Jane))
);



use MessageX\Service\Email\ValueObject\Email;
use MessageX\Service\Email\ValueObject\Body\Body;
use MessageX\Service\Email\EmailClient;

$emailClient = new EmailClient([
        'credentials' => ['key' => 'XXXXX', 'secret' => 'XXXXX']
    ]);

$emailClient->sendEmail(
    (new Email('John Doe <[email protected]>', ['Jane Doe <[email protected]>']))
        ->setSubject('Greetings')
        ->addBcc(['John Doe <[email protected]>'])
        ->addCc(['John Doe <[email protected]>'])
        ->addBody(new Body('text/plain', 'Hi Jane'))
);



use MessageX\Service\Email\ValueObject\Email;
use MessageX\Service\Email\ValueObject\Body\Body;
use MessageX\Service\Email\ValueObject\Attachment\Attachment;
use MessageX\Service\Email\EmailClient;

$emailClient = new EmailClient([
        'credentials' => ['key' => 'XXXXX', 'secret' => 'XXXXX']
    ]);

$emailClient->sendEmail(
    (new Email('John Doe <[email protected]>', ['Jane Doe <[email protected]>']))
        //... Code removed
        ->addAttachment(Attachment::fromFile('path/to/file.pdf'))
);




use MessageX\Service\Email\ValueObject\Email;
use MessageX\Service\Email\ValueObject\Body\Body;
use MessageX\Service\Email\ValueObject\Attachment\Attachment;
use MessageX\Service\Email\EmailClient;

$emailClient = new EmailClient([
        'credentials' => ['key' => 'XXXXX', 'secret' => 'XXXXX']
    ]);

$emailClient->sendEmail(
    (new Email('John Doe <[email protected]>', ['Jane Doe <[email protected]>']))
        //... Code removed
        ->addTag('Tag1')
);



use MessageX\Service\Email\ValueObject\Email;
use MessageX\Service\Email\ValueObject\Body\Body;
use MessageX\Service\Email\ValueObject\Attachment\Attachment;
use MessageX\Service\Email\EmailClient;

$emailClient = new EmailClient([
        'credentials' => ['key' => 'XXXXX', 'secret' => 'XXXXX']
    ]);

$emailClient->sendEmail(
    (new Email('John Doe <[email protected]>', ['Jane Doe <[email protected]>']))
        //... Code removed
        ->addHeader('X-Custom-Header', 'Value')
);



use MessageX\Service\Email\ValueObject\Email;
use MessageX\Service\Email\ValueObject\Body\Body;
use MessageX\Service\Email\ValueObject\Attachment\Attachment;
use MessageX\Service\Email\EmailClient;

$emailClient = new EmailClient([
        'credentials' => ['key' => 'XXXXX', 'secret' => 'XXXXX']
    ]);

$emailClient->sendEmail(
    (new Email('John Doe <[email protected]>', ['Jane Doe <[email protected]>', 'Alice Doe <[email protected]>']))
        //... Code removed
        ->addBody(new Body('text/plain', 'Hi {{name}}'))
        ->addSubstitution('name', ['Jane', 'Alice'])
);
json
    {
        "gex/email-php-sdk": "~1.0"
        }
    }
bash
composer