Skip to content
This repository has been archived by the owner on Jun 10, 2019. It is now read-only.

Latest commit

 

History

History
218 lines (148 loc) · 4.45 KB

readme.md

File metadata and controls

218 lines (148 loc) · 4.45 KB

Swift Mailer Laravel Bundle

The power of Swift Mailer with the beauty of Laravel.

Installation

Install using the Artian CLI:

php artisan bundle:install messages

then edit application/bundles.php to autoload messages:

<?php

return array(

'messages' => array(
	'auto' => true
),

You can then set your configuration at config/config.php.

A Few Examples

Changing configurations in runtime

<?php

Config::set('messages::config.transports.smtp.host', 'smtp.gmail.com');
Config::set('messages::config.transports.smtp.port', 465);
Config::set('messages::config.transports.smtp.username', '[email protected]');
Config::set('messages::config.transports.smtp.password', 'password');
Config::set('messages::config.transports.smtp.encryption', 'ssl');

Sending a message:

Sending a message couldn't be easier.

<?php

Message::send(function($message)
{
	$message->to('[email protected]');
	$message->from('[email protected]', 'Bob Marley');

	$message->subject('Hello!');
	$message->body('Well hello Someone, how is it going?');
});

Or, you can simply chain the methods directly from the Message class.

<?php

Message::to('[email protected]')
	->from('[email protected]', 'Bob Marley')
	->subject('Hello!')
	->body('Well hello Someone, how is it going?')
	->send();

Sending an email with HTML

<?php

Message::send(function($message)
{
	$message->to('[email protected]');
	$message->from('[email protected]', 'Bob Marley');
	$message->subject('Hello!');

	$message->body('Well hello <b>Someone</b>, how is it going?');

	$message->html(true);
});

Using Views

Emails with HTML can become quite cumbersome. Therefore, it is recommended that you store your emails in views.

<?php

Message::send(function($message)
{
	$message->to('[email protected]');
	$message->from('[email protected]', 'Bob Marley');

	$message->subject('Hello!');
	$message->body('view: emails.hello');

	// You can add View data by simply setting the value
	// to the message.
	$message->body->name = 'Someone';

	$message->html(true);
});

Sending an email with an attachment

<?php

Message::send(function($message)
{
	$message->to('[email protected]');
	$message->from('[email protected]', 'Bob Marley');

	$message->subject('Hello!');
	$message->body('Well hello Someone, how is it going?');

	$message->attach('/path/to/file.extension');
	
	// or:
	$generated_content = 'Some content';
	
	$message->attach($generated_content, 'file-name.extension', 'mime/type');
});

Sending emails to multiple email addresses

<?php

Message::send(function($message)
{
	$message->to(array('[email protected]', '[email protected]' => 'name'));
	$message->cc('[email protected]');
	$messages->bcc(array('[email protected]' => 'Another name', '[email protected]'));

	$message->from('[email protected]', 'Bob Marley');
	$message->subject('Hello!');
	$message->body('I really like spamming people!');
});

Sending an email with a reply address

<?php

Message::send(function($message)
{
	$message->to('[email protected]');
	$message->from('[email protected]', 'Bob Marley');
	$message->reply('[email protected]');

	$message->subject('Hello!');
	$message->body('Well hello Someone, how is it going?');
});

Checking if the message was sent

<?php

Message::send(function($message)
{
	$message->to(array('[email protected]', '[email protected]' => 'name'));
	$message->cc('[email protected]');
	$messages->bcc(array('[email protected]' => 'Another name', '[email protected]'));

	$message->from('[email protected]', 'Bob Marley');
	$message->subject('Hello!');
	$message->body('I really like spamming people!');
});

if(Message::was_sent())
{
	echo 'Sweet it worked!';
}

// You can even check if a specific email address received
// the message.
if(Message::was_sent('[email protected]'))
{
	echo 'Someone got the email!';
} 

Swift Mailer, by Chris Corbyn

Swift Mailer is a component based mailing solution for PHP 5. It is released under the LGPL license.

Swift Mailer is highly object-oriented by design and lends itself to use in complex web application with a great deal of flexibility.

For full details on usage, see the documentation.