Swift Mailer Laravel Bundle
The power of Swift Mailer with the beauty of Laravel.
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.
<?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', 'someone@gmail.com');
Config::set('messages::config.transports.smtp.password', 'password');
Config::set('messages::config.transports.smtp.encryption', 'ssl');
Sending a message couldn't be easier.
<?php
Message::send(function($message)
{
$message->to('someone@gmail.com');
$message->from('me@gmail.com', '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('someone@gmail.com')
->from('me@gmail.com', 'Bob Marley')
->subject('Hello!')
->body('Well hello Someone, how is it going?')
->send();
<?php
Message::send(function($message)
{
$message->to('someone@gmail.com');
$message->from('me@gmail.com', 'Bob Marley');
$message->subject('Hello!');
$message->body('Well hello <b>Someone</b>, how is it going?');
$message->html(true);
});
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('someone@gmail.com');
$message->from('me@gmail.com', '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);
});
<?php
Message::send(function($message)
{
$message->to('someone@gmail.com');
$message->from('me@gmail.com', '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');
});
<?php
Message::send(function($message)
{
$message->to(array('someone@gmail.com', 'email@address.com' => 'name'));
$message->cc('more@addresses.com');
$messages->bcc(array('evenmore@address.com' => 'Another name', 'onelast@address.com'));
$message->from('me@gmail.com', 'Bob Marley');
$message->subject('Hello!');
$message->body('I really like spamming people!');
});
<?php
Message::send(function($message)
{
$message->to('someone@gmail.com');
$message->from('me@gmail.com', 'Bob Marley');
$message->reply('replytome@gmail.com');
$message->subject('Hello!');
$message->body('Well hello Someone, how is it going?');
});
<?php
Message::send(function($message)
{
$message->to(array('someone@gmail.com', 'email@address.com' => 'name'));
$message->cc('more@addresses.com');
$messages->bcc(array('evenmore@address.com' => 'Another name', 'onelast@address.com'));
$message->from('me@gmail.com', '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('someone@gmail.com'))
{
echo 'Someone got the email!';
}
Swift Mailer is a component based mailing solution for PHP 5. It is released under the LGPL license.
- Homepage: http://swiftmailer.org
- Documentation: http://swiftmailer.org/docs
- Mailing List: http://groups.google.com/group/swiftmailer
- Bugs: https://github.com/swiftmailer/swiftmailer/issues
- Repository: https://github.com/swiftmailer/swiftmailer
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.