Coder Social home page Coder Social logo

simplemail's Introduction

SimpleMail class 0.7.12

A simple mail composer, phpmailer alternative, SMTP client.
UTF-8 html messages and attachements supported.

Basic Usage

$mail = new Shuchkin\SimpleMail();
$mail->setFrom('[email protected]')
	->setTo('[email protected]')
	->setSubject('Test SimpleMail')
	->setText('Hi, Sergey!')
	->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/simplemail

or download class here

Fabric

// setup mail
$mail = new Shuchkin\SimpleMail();
$mail->setFrom('[email protected]', 'Example');
 
// fabric method to( $toEmail )
$mail->to('[email protected]')
	->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('[email protected]', 'New Account', 'https://example.com/useradmin/123')->send();

SMTP

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

$mail->setFrom('[email protected])
	->setTo('[email protected]')
	->setSubject('Test SMTP')
	->setText('Yandex SMTP secured server')
	->send();

Attachments & reply

$mail = new Shuchkin\SimpleMail();
$mail->setFrom('[email protected]')
	->setTo('[email protected]')
	->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('[email protected]')
	->send();

Priority & custom headers

$mail = new Shuchkin\SimpleMail();
$mail->setFrom('[email protected]')
	->setTo('[email protected]')
	->setSubject('WARNING!')
	->setText('SERVER DOWN!')
	->setPriority('urgent')
	->setCustomHeaders(['Cc' => '[email protected]'])
	->send();

Custom transport

$mail = new Shuchkin\SimpleMail( function( $mail, $encoded ) {
	print_r( $encoded );	
});
$mail->setFrom('[email protected]')
	->setTo('[email protected]')
	->setSubject('WARNING!')
	->setText('SERVER DOWN!')
	->send();

/*
Array
(
    [from] => [email protected]
    [to] => [email protected]
    [subject] => =?UTF-8?B?V0FSTklORyE=?=
    [message] => SERVER DOWN!
    [headers] => To: [email protected]
Subject: =?UTF-8?B?V0FSTklORyE=?=
X-Mailer: PHP/7.2.14
MIME-Version: 1.0
From: [email protected]
Reply-To: [email protected]
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)

History

0.7.12 (2022-02-04) PHP/5.3 support
0.7.11 (2019-02-18) Initial release

simplemail's People

Contributors

shuchkin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.