Skip to content
Stefano Azzolini edited this page Mar 23, 2017 · 4 revisions

The Email modules will allow you to send email messages via various services providers.

Choosing the email service


You can choose the Email service via the using method. The optional second parameter is dictionary of init paramenters to pass to the selected driver.

The default driver is Native, the a service that uses the PHP mail function.

Email::using('native');

Init a service with parameters :

Email::using('SMTP',[
  'host' => 'smtp.starkindustries.com',
  'port' => 25,
  'username' => 'tony',
  'password' => 'pepperpotts',
]);

Sending an email


You can send an email with the chosen service via the Email::send method.

An associative array must be passed with the email definition.

Email::send([
  'to'       =>  'info@shield.com',
  'from'     =>  'Tony <tony@starkindustries.com>',
  'subject'  =>  'About your proposal...',
  'message'  =>  '<b>NOT</b> interested.',
]);

Sending an email with attachments


You can add attachments passing file URLs to the attachments key :

Email::send([
  'to'           =>  'Bruce <dr.banner@greenrelax.com>',
  'from'         =>  'Tony <tony@starkindustries.com>',
  'subject'      =>  'Jarvis Code Matrix',
  'message'      =>  "Hey Pea, I'm sending you the AI code matrix of Jarvis.",
  'attachments'  =>  '/usr/home/tony/jarvis.matrix.dat',
]);

The attachments key also accept an array of multiple file descriptors :

  • Local file paths
  • URLs
  • Raw content
  'attachments'  =>  [
      '/usr/home/tony/jarvis.matrix.dat',
      'http://vignette3.wikia.nocookie.net/marvelcentral/images/6/61/Iron_man_tony_stark_hi_res.jpg',
      [
         'name'    => 'report.csv',
         'content' => "A,B,C,D\n1,2,3,4\n5,6,7,8",
      ],
  ],

Email address formats


The to and from properties accepts one or an array of email addresses in these formats :

  1. user@host.com
  2. <user@host.com>
  3. Name Surname <user@host.com>

Clone this wiki locally