PHP code example of berlioz / mailer

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

    

berlioz / mailer example snippets


use Berlioz\Mailer\Address;
use Berlioz\Mailer\Mail;
use Berlioz\Mailer\Mailer;

$mail = (new Mail())
            ->setSubject('Test of Berlioz/Mailer')
            ->setText('Text plain of my mail')
            ->setHtml('<p>Html text of my mail</p>')
            ->setFrom(new Address('[email protected]', 'Me the sender'))
            ->setTo([new Address('[email protected]', 'The recipient')]); 

$mailer = new Mailer();
$mailer->send($mail);

use Berlioz\Mailer\Address;
use Berlioz\Mailer\Mail;

$mail = new Mail();
$mail->setSubject('Subject of my mail')
     ->setText('Text plain of my mail')
     ->setHtml('<p>Html text of my mail</p>')
     ->setFrom(new Address('[email protected]', 'Me the sender'))
     ->setTo([new Address('[email protected]', 'The recipient')]);

use Berlioz\Mailer\Attachment;use Berlioz\Mailer\Mail;$attachment = new Attachment('/path/of/my/file.pdf');
$mail = new Mail();
$mail->addAttachment($attachment);

use Berlioz\Mailer\Attachment;use Berlioz\Mailer\Mail;$attachment = new Attachment('/path/of/my/img.jpg');
$mail = new Mail();
$mail->addAttachment($attachment);

$html = '<p>Html content 1</p>';
$html .= '<img src="cid:' . $attachment->getId() . '">';
$html .= '<p>Html content 2</p>';

$mail->setHtml($html);

use Berlioz\Mailer\Mailer;
use Berlioz\Mailer\Transport\Smtp;

$smtp = new Smtp(
    'smpt.test.com',
    '[email protected]',
    'password',
    25,
    ['timeout' => 5]
);
$mailer = new Mailer();
$mailer->setTransport($smtp);

use Berlioz\Mailer\Mailer;
$mailer = new Mailer([
    'transport' => [
        'name' => 'smtp',
        'arguments' => [
            'host' => 'smpt.test.com',
            'username' => '[email protected]',
            'password' => 'password',
            'port' => 25,
            'options' => ['timeout' => 5]
        ]
    ]
]);