dev-master
9999999-dev https://github.com/parfumix/mailerMailer based on swift mailer.
MIT
The Requires
- php >=7.0.0
- swiftmailer/swiftmailer 5.x
- monolog/monolog 1.x-dev
by Radu
mailer swift-mailer
Mailer based on swift mailer.
Mailer is a simple package based on SwiftMailer which allow sending messages with different drivers., (*1)
You can use the composer
package manager to install. Either run:, (*2)
$ php composer.phar require parfumix/mailer "dev-master"
or add:, (*3)
"parfumix/mailer": "dev-master"
to your composer.json file, (*4)
If you use DotEnv package all you have to do is to populate your .env file., (*5)
MAIL_DRIVER=smtp // Allow to select transport MAIL_HOST=smtp.gmail.com MAIL_PORT=465 MAIL_USERNAME=your_gmail@gmail.com MAIL_PASSWORD=your_password MAIL_ENCRYPTION=ssl
and start using, (*6)
$mailer = (new Mailer( new Mailer\Transport ))->alwaysFrom('your_email_always_from@gmail.com', 'Your name') ->alwaysReplyTo('reply_to@gmailcom', 'Reply name');
If you use other storage repository you can create new Mailer instance and populate with config data from array, (*7)
$config = array( 'driver' => 'smtp', 'host' => 'smtp.gmail.com', 'port' => 465, 'username' => 'you_email@gmail.com', 'password' => 'your_passwd', 'encryption' => 'ssl' ); $mailer = (new Mailer\Mailer( new Mailer\Transport( $config ) ))->alwaysFrom('your_email_always_from@gmail.com', 'Your name') ->alwaysReplyTo('reply_to@gmailcom', 'Reply name');
If you want add custom transport all you have to do is to create new transport class which implement TransportAble, (*8)
class ArrayTransport extends Transport implements TransportAble { /** * {@inheritdoc} */ public function send(Swift_Mime_Message $message, &$failedRecipients = null) { $this->beforeSendPerformed($message); // Send your message return $this->numberOfRecipients($message); } }
And register driver to Transport class., (*9)
$tranport = (new Mailer\Transport([ 'driver' => 'my_driver' ]))->extend('my_driver', function($transport) { return new ArrayTransport() }); $mailer = (new Mailer($tranport)) ->alwaysFrom('your_email_always_from@gmail.com', 'Your name') ->alwaysReplyTo('reply_to@gmailcom', 'Reply name');
You can use directly Mailer and send messages by using ::to('to_email@gmail.com') method, (*10)
$mailer->to('to_email@gmail.com', 'Subject') ->send('This is a test message'); $mailer->to('to_email@gmail.com', 'Subject')->send('Message body', null, function (\Mailer\Message $message) { return $message->setFrom('other_from_email@gmail.com'); });
or you can create Mailable classes which require build method, (*11)
class NewPayment extends \Mailer\Mail implements \Mailer\Mailable { public function build() { $this->text('Body message'); } } $mailer->to(array( 'to_email@gmail.com' ))->send( new NewPayment('Subject message') );
You can change driver using with method:, (*12)
$mailer->to('to_email@gmail.com', 'Subject') ->with('sendmail') ->send('This is a test message');
Mailer based on swift mailer.
MIT
mailer swift-mailer