Most email libraries are old and don't have what we consider a good interface, also we had the case that we needed to switch the underlying implementation. This library makes it both very convenient, it offers a fluid and strict typed interface to build emails and sending them through any mailer you want.
This library mostly implements just an email entity that is passed to a mailer that takes care of the actual email sending. It shouldn't be possible to create and send an email with an invalid state with this library.
- Swift Mailer (recommended)
- PHPMailer
Other included mailers:
- mail() Mailer - a very simple implementation using mail()
- Log Mailer - for testing, requires a PSR3 compatible logger
- Null Mailer - for testing
Assuming you want to use this library with the Swift mailer:
composer require phauthentic/email
composer require swiftmailer/swiftmailer
Be aware that the library doesn't come with a default mailer library dependency! You MUST choose one that is supported!
A simple example:
use Phauthentic\Email\Email;
use Phauthentic\Email\EmailAddress;
use Phauthentic\Email\Mailer\SwiftMailer;
use Swift_Mailer;
use Swift_SmtpTransport;
$email = (new Email());
->setSender(new EmailAddress('me@test.com', 'Senders Name'))
->addReceiver(new EmailAddress('you@test.com'))
->setSubject('A test')
->setTextContent('My text email')
->setHtmlContent('<p>My HTML content</p>');
$mailer = new SwiftMailer(new Swift_Mailer(new Swift_SmtpTransport()));
$mailer->send($email);
$mailer->send($anotherEmail);
$mailer->send($oneMore);
Please open a feature type issue on Github with a detailed description and with an example of how to archive what you want in your mailer. Or even better: Create a pull request!
Licensed under the MIT license.
Copyright (c) Phauthentic