-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmail.html
144 lines (100 loc) · 6.64 KB
/
mail.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>Mail</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="css/ubuntu-font.css">
<script src="vendor/modernizr-2.6.2.min.js"></script>
<script type="text/javascript" src="vendor/google-code-prettify/prettify.js"></script>
</head><body><section class="docs-content"><div class="container">
<article class="docs-body"><h1>Mail</h1>
<p><a name="configuration"></a></p>
<h2>Configuration</h2>
<p>Laravel provides a clean, simple API over the popular <a href="http://swiftmailer.org">SwiftMailer</a> library. The mail configuration file is <code>app/config/mail.php</code>, and contains options allowing you to change your SMTP host, port, and credentials, as well as set a global <code>from</code> address for all messages delivered by the library. You may use any SMTP server you wish. If you wish to use the PHP <code>mail</code> function to send mail, you may change the <code>driver</code> to <code>mail</code> in the configuration file. A <code>sendmail</code> driver is also available.</p>
<p><a name="basic-usage"></a></p>
<h2>Basic Usage</h2>
<p>The <code>Mail::send</code> method may be used to send an e-mail message:</p>
<pre class="prettyprint"><code>Mail::send('emails.welcome', $data, function($message)
{
$message->to('[email protected]', 'John Smith')->subject('Welcome!');
});
</code></pre>
<p>The first argument passed to the <code>send</code> method is the name of the view that should be used as the e-mail body. The second is the <code>$data</code> that should be passed to the view, and the third is a Closure allowing you to specify various options on the e-mail message.</p>
<blockquote>
<p><strong>Note:</strong> A <code>$message</code> variable is always passed to e-mail views, and allows the inline embedding of attachments. So, it is best to avoid passing a <code>message</code> variable in your view payload.</p>
</blockquote>
<p>You may also specify a plain text view to use in addition to an HTML view:</p>
<pre class="prettyprint"><code>Mail::send(array('html.view', 'text.view'), $data, $callback);
</code></pre>
<p>Or, you may specify only one type of view using the <code>html</code> or <code>text</code> keys:</p>
<pre class="prettyprint"><code>Mail::send(array('text' => 'view'), $data, $callback);
</code></pre>
<p>You may specify other options on the e-mail message such as any carbon copies or attachments as well:</p>
<pre class="prettyprint"><code>Mail::send('emails.welcome', $data, function($message)
{
$message->from('[email protected]', 'Laravel');
$message->to('[email protected]')->cc('[email protected]');
$message->attach($pathToFile);
});
</code></pre>
<p>When attaching files to a message, you may also specify a MIME type and / or a display name:</p>
<pre class="prettyprint"><code>$message->attach($pathToFile, array('as' => $display, 'mime' => $mime));
</code></pre>
<blockquote>
<p><strong>Note:</strong> The message instance passed to a <code>Mail::send</code> Closure extends the SwiftMailer message class, allowing you to call any method on that class to build your e-mail messages.</p>
</blockquote>
<p><a name="embedding-inline-attachments"></a></p>
<h2>Embedding Inline Attachments</h2>
<p>Embedding inline images into your e-mails is typically cumbersome; however, Laravel provides a convenient way to attach images to your e-mails and retrieving the appropriate CID.</p>
<p><strong>Embedding An Image In An E-Mail View</strong></p>
<pre class="prettyprint"><code><body>
Here is an image:
<img src="<?php echo $message->embed($pathToFile); ?>">
</body>
</code></pre>
<p><strong>Embedding Raw Data In An E-Mail View</strong></p>
<pre class="prettyprint"><code><body>
Here is an image from raw data:
<img src="<?php echo $message->embedData($data, $name); ?>">
</body>
</code></pre>
<p>Note that the <code>$message</code> variable is always passed to e-mail views by the <code>Mail</code> class.</p>
<p><a name="queueing-mail"></a></p>
<h2>Queueing Mail</h2>
<p>Since sending e-mail messages can drastically lengthen the response time of your application, many developers choose to queue e-mail messages for background sending. Laravel makes this easy using its built-in <a href="/docs/queues">unified queue API</a>. To queue a mail message, simply use the <code>queue</code> method on the <code>Mail</code> class:</p>
<p><strong>Queueing A Mail Message</strong></p>
<pre class="prettyprint"><code>Mail::queue('emails.welcome', $data, function($message)
{
$message->to('[email protected]', 'John Smith')->subject('Welcome!');
});
</code></pre>
<p>You may also specify the number of seconds you wish to delay the sending of the mail message using the <code>later</code> method:</p>
<pre class="prettyprint"><code>Mail::later(5, 'emails.welcome', $data, function($message)
{
$message->to('[email protected]', 'John Smith')->subject('Welcome!');
});
</code></pre>
<p>If you wish to specify a specific queue or "tube" on which to push the message, you may do so using the <code>queueOn</code> and <code>laterOn</code> methods:</p>
<pre class="prettyprint"><code>Mail::queueOn('queue-name', 'emails.welcome', $data, function($message)
{
$message->to('[email protected]', 'John Smith')->subject('Welcome!');
});
</code></pre>
<p><a name="mail-and-local-development"></a></p>
<h2>Mail & Local Development</h2>
<p>When developing an application that sends e-mail, it's usually desirable to disable the sending of messages from your local or development environment. To do so, you may either call the <code>Mail::pretend</code> method, or set the <code>pretend</code> option in the <code>app/config/mail.php</code> configuration file to <code>true</code>. When the mailer is in <code>pretend</code> mode, messages will be written to your application's log files instead of being sent to the recipient.</p>
<p><strong>Enabling Pretend Mail Mode</strong></p>
<pre class="prettyprint"><code>Mail::pretend();
</code></pre>
</article><div class="clearfix"></div>
</div>
</section>
<script src="js/jquery.min.js"></script>
<script src="js/plugins.js"></script>
<script type="text/javascript" src="vendor/google-code-prettify/run_prettify.js"></script>
</body></html>