Skip to content

Latest commit

 

History

History
91 lines (64 loc) · 2.65 KB

mail.md

File metadata and controls

91 lines (64 loc) · 2.65 KB

Mail

Configuration

The mail configuration file is app/config/mail.php, and contains options allowing you to change your SMTP host, port, and credentials, as well as the from address. If you wish to use the PHP mail function or sendmail you may change the driver in the configuration file.

SMTP Example

'driver' => 'smtp',
'host' => 'mail.example.com',
'port' => 587,
'from' => array('address' => '[email protected]', 'name' => 'My Website'),
'encryption' => 'tls',
'username' => '[email protected]',
'password' => 'mail-password',

Gmail Example

If you don't have an e-mail on your server you can even use a Gmail account.

'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 587,
'from' => array('address' => '[email protected]', 'name' => 'My Website'),
'encryption' => 'tls',
'username' => '[email protected]',
'password' => 'your-gmail-password',

API Drivers

There Mailgun, Mandrill and SparkPost api drivers require PHP >= 5.4.

Mailgun

Copy your Mailgun API Key and Domain to app/config/services.php under the mailgun section:

'mailgun' => array(
    'secret' => 'your-mailgun-key',
    'domain' => 'your-mailgun-domain'
),

Mandrill

Copy your Mandrill API Key to app/config/services.php under the mandrill section:

'mandrill' => array(
    'secret' => 'your-mandrill-key',
),

SparkPost

Copy your SparkPost API Key to app/config/services.php under the sparkpost section:

'sparkpost' => array(
    'secret' => 'your-sparkpost-key',
),

Templates

The e-mail templates are stored in app/views/emails/. These are used when sending the activation e-mail, the password reminder, etc.

Basic Usage

If you want to send your custom e-mails you can use Mail::send method:

$data = array('body' => 'Welcome to My Website!');

Mail::send('emails.welcome', $data, function($message) {
    $message->to('[email protected]', 'John Doe');
    $message->subject('Welcome!');
});

The first argument passed to the send method is the name of the view (app/views/emails/welcome.php) that should be used as the e-mail body. The second is the $data that should be passed to the view, and the third is a Closure allowing you to specify various options on the e-mail message.

For all the methods available on the $message instance please see src/Hazzard/Mail/Message.php.