PHP code example of oliver-schoendorn / mailer

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

    

oliver-schoendorn / mailer example snippets




use OS\Mail\Mail;

$mail = (new Mail())
    ->setSubject('email subject')
    ->setSender('[email protected]', 'Foo Bar')
    ->setFrom('[email protected]', 'Foo Bar')
    ->setTo('[email protected]', 'Receipt name');



use OS\Mail\MailAttachment;

$inlineImage = (new MailAttachment('file.jpg'))
   ->setContent(fopen('path/to/file.jpg', 'r'))
   ->setMimeType('image/jpg');

$mail->addInlineAttachment($inlineImage);



use Zend\Mime\Mime;
use OS\Mail\MailBody;

$mail->addBodyPart((new MailBody())
    ->setMimeType(Mime::TYPE_TEXT)
    ->setContent('Plain text mail content'));

$mail->addBodyPart((new MailBody())
    ->setMimeType(Mime::TYPE_HTML)
    ->setContent('<html><body><p>Html mail content<img src="' . $inlineImage . '" /></p></body></html>'));


use OS\Mail\MailAttachment;

$mail->addAttachment((new MailAttachment('file.jpg'))
    ->setContent(fopen('path/to/file.jpg', 'r'))
    ->setMimeType('image/jpg'));


use OS\Mail\MailTransportFactory;

$mailTransport = (new MailTransportFactory())->createSmtpTransportWithLogin(
    $config['mail']['user'],
    $config['mail']['pass'],
    $config['mail']['encryption'],
    $config['mail']['name'],
    $config['mail']['host'],
    $config['mail']['port']
);

$mail->send($mailTransport);