wscore / mail
mail related package
1.0.0
2015-10-02 06:33 UTC
Requires
- swiftmailer/swiftmailer: ^5.0
This package is not auto-updated.
Last update: 2024-11-03 08:05:34 UTC
README
Wrapper classes for SwiftMailer to simplify some operations.
- Framework agnostic.
- License: MIT License.
- PSR: PSR-1, PSR-2, and PSR-4.
Basic Usage
It's as simple as 1, 2, and 3...
use WScore\Mail\Transport\Transport; use WScore\Mail\Mailer; // 1. create a transport $transport = Transport::forgeSmtp(); // 2. create a mailer $mailer = Mailer::newInstance($transport); // 3. send mails $mailer->sendText('hello world', function(Swift_Message $message) { $message->setTo('test@example.com', 'tested'); });
Message Default
You can create a MessageDefault
object to set a default message in Mailer
. The methods in MessageDefault
objects, which start with with
, are immutable call.
// somewhere in a config file. use WScore\Mail\MessageDefault; $default = MessageDefault::newInstance() ->withFrom('from@example.com', 'from address'); ->withReturnPath('bad-mail@example.com') ->withReplyTo('sender@example.com', 'sender name'); $mailer = Mailer::newInstance($transport) ->setMessageDefault($default); // later on... $mailer->setMessageDefault( $mailer->getMessageDefault()->withBulk() // send bulk mail? ); $mailer->sendHtml('<h1>hi</h1>', function(Swift_Message $message) { $message->setTo('to@example.com'); });
Or, just use a closure as MessageDefault.
Japanese ISO-2022
sending Japanese in ISO2022 encoding. You must call Transport::goJapaneseIso2022()
and use $mailer->sendJIS(...)
method as;
Transport::goJapaneseIso2022(); $transport = Transport::forgeSmtp(); $mailer = Mailer::newInstance($transport); $mailer->sendJIS('some japanese text here', function(Swift_Message $message) { $message->setTo('test@example.com', 'tested'); });
Use SMTP transport when sending emails in ISO2022 encoding based on my experience...