Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/shuchkin/react-smtp-client
ReactPHP async SMTP Client to send a simple email
https://github.com/shuchkin/react-smtp-client
Last synced: 4 days ago
JSON representation
ReactPHP async SMTP Client to send a simple email
- Host: GitHub
- URL: https://github.com/shuchkin/react-smtp-client
- Owner: shuchkin
- License: mit
- Created: 2019-02-03T07:08:34.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-02-19T04:18:26.000Z (over 4 years ago)
- Last Synced: 2024-11-02T10:07:50.662Z (11 days ago)
- Language: PHP
- Size: 10.7 KB
- Stars: 22
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
react-smtp-client v0.2
======================[ReactPHP](https://reactphp.org/) async SMTP client to send a emails like php
mail(). Simple UTF-8 text/plain messages out-of-the-box.Basic Usage
-----------~~~php
$loop = \React\EventLoop\Factory::create();$smtp = new \Shuchkin\ReactSMTP\Client( $loop ); // localhost:25
$smtp->send('[email protected]', '[email protected]', 'Test ReactPHP mailer', 'Hello, Sergey!')->then(
function() {
echo 'Message sent'.PHP_EOL;
},
function ( \Exception $ex ) {
echo 'SMTP error '.$ex->getCode().' '.$ex->getMessage().PHP_EOL;
}
);$loop->run();
~~~Google SMTP Server – How to send bulk emails for free
-----------------------------------------------------~~~php
$loop = \React\EventLoop\Factory::create();$smtp = new \Shuchkin\ReactSMTP\Client( $loop, 'tls://smtp.gmail.com:465', '[email protected]','password' );
$recipients = ['[email protected]','[email protected]'];
foreach( $recipients as $to ) {
$smtp->send('[email protected]', $to, 'Test ReactPHP mailer', 'Hello, Sergey!')->then(
function() use ( $to ) {
echo 'Message to '.$to.' sent via Google SMTP'.PHP_EOL;
},
function ( \Exception $ex ) use ( $to ) {
echo 'Message to '.$to.' not sent: '.$ex->getMessage().PHP_EOL;
}
);
}$loop->run();
~~~Google limit for personal SMTP 99 messages per 24 hours.
Using mime/mail class, send mails and attachments
-------------------------------------------------See https://github.com/shuchkin/simplemail
~~~bash
$ composer require shuchkin/simplemail
~~~~~~php
$smtp = new \Shuchkin\ReactSMTP\Client( $loop, 'example.com:25', 'username', 'password' );// setup fabric
$sm = new \Shuchkin\SimpleMail();
$sm->setFrom( '[email protected]' );
$sm->setTransport( function ( \Shuchkin\SimpleMail $m, $encoded ) use ( $smtp ) {$smtp->send( $m->getFromEmail(), $encoded['to'], $encoded['subject'], $encoded['message'], $encoded['headers'] )
->then(
function () {
echo "\r\nSent mail";
},
function ( \Exception $ex ) {
echo "\r\n" . $ex->getMessage();
}
);
});// send mail
$sm->to( ['[email protected]', '[email protected]'] )
->setSubject('Async mail with ReactPHP')
->setText('Async mail sending perfect! See postcard')
->attach('image/postcard.jpg')
->send();
~~~Install
-------The recommended way to install this library is [through
Composer](https://getcomposer.org). [New to
Composer?](https://getcomposer.org/doc/00-intro.md)This will install the latest supported version:
~~~bash
$ composer require shuchkin/react-smtp-client
~~~Changelog
---------0.2 (2020-02-19) - basic UTF-8 text/plain messages out-of-the-box, ReactPHP
actual versions in composer.json0.1.1 (2019-03-12) - Initial release