shuchkin/react-smtp-client

ReactPHP async SMTP Client

0.1.1 2019-03-12 14:40 UTC

This package is auto-updated.

Last update: 2019-12-31 00:31:53 UTC


README

68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e742e7376673f75726c3d6874747073253341253246253246736869656c6473696f2d70617472656f6e2e6865726f6b756170702e636f6d25324673687563686b696e

ReactPHP async SMTP client to send a simple email.

Basic Usage

$loop = \React\EventLoop\Factory::create();

$smtp = new \Shuchkin\ReactSMTP\Client( $loop ); // localhost:25

$smtp->send('info@example.org', 'sergey.shuchkin@gmail.com', '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 Emails for Free

$loop = \React\EventLoop\Factory::create();

$smtp = new \Shuchkin\ReactSMTP\Client( $loop, 'tls://smtp.gmail.com:465', 'username@gmail.com','password' );

$smtp->send('username@gmail.com', 'sergey.shuchkin@gmail.com', 'Test ReactPHP mailer', 'Hello, Sergey!')->then(
	function() {
		echo 'Message sent via Google SMTP'.PHP_EOL;
	},
	function ( \Exception $ex ) {
		echo 'SMTP error '.$ex->getCode().' '.$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

$ composer require shuchkin/simplemail
$smtp = new \Shuchkin\ReactSMTP\Client( $loop, 'example.com:25', 'username', 'password' );

// setup fabric
$sm = new \Shuchkin\SimpleMail();
$sm->setFrom( 'example@example.com' );
$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
$m->to( ['sergey.shuchkin@gmail.com', 'reactphp@example.com'] )
	->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. New to Composer?

This will install the latest supported version:

$ composer require shuchkin/react-smtp-client