shuchkin/simplemail

PHP mail/smtp composer and mailer class

dev-master 2019-06-01 18:52 UTC

This package is auto-updated.

Last update: 2020-07-30 01:26:25 UTC


README

68747470733a2f2f696d672e736869656c64732e696f2f656e64706f696e742e7376673f75726c3d6874747073253341253246253246736869656c6473696f2d70617472656f6e2e6865726f6b756170702e636f6d25324673687563686b696e

A simple mail composer, phpmailer alternative, smtp client.

Basic Usage

$mail = new Shuchkin\SimpleMail();
$mail->setFrom('example@example.com')
	->setTo('sergey.shuchkin@gmail.com')
	->setSubject('Test SimpleMail')
	->setText('Hi, Sergey!')
	->send();

Fabric

// setup mail
$mail = new Shuchkin\SimpleMail();
$mail->setFrom('example@example.com', 'Example');
 
// fabric method to( $toEmail )
$mail->to('sergey.shuchkin@gmail.com')
	->setSubject('Account activation')
	->setHTML('<html><body><p><b>Your account has activated!</b></p></body></html>', true)
	->send();

// fabric method compose( $toEmail, $subject, $text )	
$mail->compose('admin@example.com', 'New Account', 'http://example.com/useradmin/123')->send();

SMTP

$mail = new Shuchkin\SimpleMail('smtp', [
	'host' => 'ssl://smtp.yandex.ru',
    'port'     => 465,
    'username' => 'test@yandex.ru',
    'password' => 'test'
]);

$mail->setFrom('test@yandex.ru)
	->setTo('sergey.shuchkin@gmail.com')
	->setSubject('Test SMTP')
	->setText('Yandex SMTP secured server')
	->send();

Attachments & reply

$mail = new Shuchkin\SimpleMail();
$mail->setFrom('example@example.com')
	->setTo('sergey.shuchkin@gmail.com')
	->setSubject('Test attachments')
	->setHTML('<html><body><p>See attached price list.</p><p><img src="logo.jpg" /> Logo</p></body></html>')
	->attach( __DIR__.'/doc/PriceList.pdf')
	->attach( __DIR__.'/images/logo400x300.jpg', 'logo.jpg')
	->setReply('manager@example.com')
	->send();

Priority & custom headers

$mail = new Shuchkin\SimpleMail();
$mail->setFrom('example@example.com')
	->setTo('sergey.shuchkin@gmail.com')
	->setSubject('WARNING!')
	->setText('SERVER DOWN!')
	->setPriority('urgent')
	->setCustomHeaders(['Cc' => 'admin@exmple.com'])
	->send();

Custom transport

$mail = new Shuchkin\SimpleMail( function( $mail, $encoded ) {
	print_r( $encoded );	
});
$mail->setFrom('example@example.com')
	->setTo('sergey.shuchkin@gmail.com')
	->setSubject('WARNING!')
	->setText('SERVER DOWN!')
	->send();

/*
Array
(
    [from] => example@example.com
    [to] => sergey.shuchkin@gmail.com
    [subject] => =?UTF-8?B?V0FSTklORyE=?=
    [message] => SERVER DOWN!
    [headers] => To: sergey.shuchkin@gmail.com
Subject: =?UTF-8?B?V0FSTklORyE=?=
X-Mailer: PHP/7.2.14
MIME-Version: 1.0
From: example@example.com
Reply-To: example@example.com
Date: Mon, 18 Feb 2019 13:17:28 +0000
Content-Type: text/plain; charset="UTF-8"
)
*/

Export & import

SimpleMail::toArray() - export to array
SimpleMail::fromArray( $data ) - import from assoc array (fabric)
SimpleMail::toJSON() - export to JSON
SimpleMail::fromJSON( $json ) - import from json (fabric)

Install

The recommended way to install this library is through Composer. New to Composer?

This will install the latest supported version:

$ composer require shuchkin/simplemail

History

2019-02-18 v0.7.11 Initial release