29.07.2016 Views

laravel-5

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Mail 293<br />

Building The Message<br />

As previously discussed, the third argument given to the send method is a Closure allowing you<br />

to specify various options on the e-mail message itself. Using this Closure you may specify other<br />

attributes of the message, such as carbon copies, blind carbon copies, etc:<br />

.<br />

1 Mail::send('emails.welcome', $data, function ($message) {<br />

2 $message->from('us@example.com', 'Laravel');<br />

3<br />

4 $message->to('foo@example.com')->cc('bar@example.com');<br />

5 });<br />

Here is a list of the available methods on the $message message builder instance:<br />

.<br />

1 $message->from($address, $name = null);<br />

2 $message->sender($address, $name = null);<br />

3 $message->to($address, $name = null);<br />

4 $message->cc($address, $name = null);<br />

5 $message->bcc($address, $name = null);<br />

6 $message->replyTo($address, $name = null);<br />

7 $message->subject($subject);<br />

8 $message->priority($level);<br />

9 $message->attach($pathToFile, array $options = []);<br />

10<br />

11 // Attach a file from a raw $data string...<br />

12 $message->attachData($data, $name, array $options = []);<br />

13<br />

14 // Get the underlying SwiftMailer message instance...<br />

15 $message->getSwiftMessage();<br />

Note: The message instance passed to a Mail::send Closure extends the SwiftMailer<br />

message class, allowing you to call any method on that class to build your e-mail messages.<br />

Mailing Plain Text<br />

By default, the view given to the send method is assumed to contain HTML. However, by passing<br />

an array as the first argument to the send method, you may specify a plain text view to send in<br />

addition to the HTML view:

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!