praetoriantechnology / smart-mailer
Smart mailer based on Symfony Mailer which supports dynamic source mailboxes and easy integration of files within emails
Installs: 1 296
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 2
Forks: 0
Open Issues: 0
Requires
- symfony/google-mailer: ^6.0
- symfony/mailer: ^6.0
- symfony/mime: ^6.0
- symfony/twig-bridge: ^6.0
- twig/extra-bundle: ^3.4
- twig/twig: ^3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.8
- php-mock/php-mock-phpunit: ^2.6
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-11-27 09:55:35 UTC
README
Smart mailer is a simple library which assits sending of emails with use of symfony/mailer component. At the moment it requires SMTP connection, but grants features like easy embedding of images, easier attachments adding, exceptions tracking and use of string templates instead of files.
Sample use:
<?php declare(strict_types=1); use Praetorian\SmartMailer\Attachment; use Praetorian\SmartMailer\EmailAddress; use Praetorian\SmartMailer\Message; use Praetorian\SmartMailer\SmartMailer; use Praetorian\SmartMailer\Smtp; include 'vendor/autoload.php'; $from = new EmailAddress('jaroslaw@kaczynski.pl', 'Jaroslaw Kaczynski'); $to = new EmailAddress('andrzej@duda.pl', 'Andrzej Duda'); $smtp = new Smtp(); $smtp->setHost('smtp.sample.com') ->setPort(465) ->setUsername('username') ->setPassword('password') ; $image1 = new Attachment(); $image1->setPath('sample.png') ; $message = new Message(); $message->setFrom($from) ->addTo($to) ->setHtml('<html><head><title>test</title></head><body>{{ variable }} <img src="cid:sample.png" alt="test"/></body></html>') ->addImage($image1) ->setSubject('sample mail title') ->setContext([ 'variable' => 'sample text', ]) ; $mailer = new SmartMailer($smtp); $mailer->send($message);
You can easily embed any image by using content id
of the resource. If your
filename is sample.png
then to embed just place cid:sample.png
in contents.
You can also define a custom name:
$image1->setName('othername')
Then the substitution will be cid:othername
.
Warning: it is required for the name to be unique!
Roadmap
1.0: tests, comments 2.0: other transports than SMTP Servers 3.0: Pub/Sub queues support
Contribution
Any pull requests or issues reported are more than welcome.
License
GPL 3+