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', '[email protected]');
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('[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();
<?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);
});
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);
});
<?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');
});
<?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!');
});
<?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?');
});
<?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 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.