Readouble

Laravel 4.2 メール

設定Configuration

Laravelは人気のあるSwiftMailerライブラリーのクリーンでシンプルなAPIを提供しています。メールの設定ファイルはapp/config/mail.phpです。SMTPホスト、ポート、認証、更にライブラリーが送信するメッセージ全部に対するグローバルな送信元(from)アドレスなどを設定するオプションが用意されています。お好きなSMTPサーバーをご利用できます。メールの送信にPHPのmail機能を使用したい場合は、設定ファイルのdraivermailに変更してください。 sendmailドライバーも使用できます。Laravel provides a clean, simple API over the popular SwiftMailer[http://swiftmailer.org] library. 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 set a global from address for all messages delivered by the library. You may use any SMTP server you wish. If you wish to use the PHP mail function to send mail, you may change the driver to mail in the configuration file. A sendmail driver is also available.

APIドライバーAPI Drivers

Laravelではさらに、MailgunとMandrillのHTTP APIドライバーを用意しています。これらのAPIは大抵の場合、SMTPサーバーよりもシンプルで早いです。両方のドライバー共に、Guzzle 4 HTTPライブラリーをアプリケーションにインストールする必要があります。以下の行をcomposer.jsonファイルに追加し、Guzzle 4をプロジェクトに追加してください。Laravel also includes drivers for the Mailgun and Mandrill HTTP APIs. These APIs are often simpler and quicker than the SMTP servers. Both of these drivers require that the Guzzle 4 HTTP library be installed into your application. You can add Guzzle 4 to your project by adding the following line to your composer.json file:

"guzzlehttp/guzzle": "~4.0"

MailgunドライバーMailgun Driver

Mailgunドライバーを使用するには、app/config/mail.php設定ファイル中のdriverオプションをmailgunに設定してください。次に、app/config/services.php設定ファイルが、プロジェクトに存在していなければ作成してください。中身を以下のオプションにしてください。To use the Mailgun driver, set the driver option to mailgun in your app/config/mail.php configuration file. Next, create an app/config/services.php configuration file if one does not already exist for your project. Verify that it contains the following options:

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

MandrillドライバーMandrill Driver

Mandrillドライバーを使用するには、app/config/mail.php設定ファイル中のdriverオプションを、mandrillに設定してください。次に、app/config/services.php設定ファイルが、プロジェクトに存在していなければ作成してください。中身を以下のオプションにしてください。To use the Mandrill driver, set the driver option to mandrill in your app/config/mail.php configuration file. Next, create an app/config/services.php configuration file if one does not already exist for your project. Verify that it contains the following options:

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

ログドライバーLog Driver

app/config/mail.php設定ファイルのdriverオプションをlogに設定すると、全てのログファイルがログファイルに書き込まれます。そして、どの受取人に対しでも、実際には送信されなくなります。これは主に、素早くローカルでデバッグするときや、内容を確認する場合に便利です。If the driver option of your app/config/mail.php configuration file is set to log, all e-mails will be written to your log files, and will not actually be sent to any of the recipients. This is primarily useful for quick, local debugging and content verification.

基本的な使い方Basic Usage

Mail::sendメソッドはメールメッセージを送信するために使用されます。The Mail::send method may be used to send an e-mail message:

Mail::send('emails.welcome', array('key' => 'value'), function($message)
{
	$message->to('foo@example.com', 'John Smith')->subject('Welcome!');
});

sendメソッドに渡される最初の引数は、メールの本文に使用されるビューの名前です。2つ目の引数はビューに渡されるデーターで、ほとんどの場合連想配列です。ビュー中、$keyにより、データーのアイテムを参照できます。3つ目はクロージャーで、メッセージに様々なオプションを指定するために使用します。The first argument passed to the send method is the name of the view that should be used as the e-mail body. The second is the data to be passed to the view, often as an associative array where the data items are available to the view by $key. The third is a Closure allowing you to specify various options on the e-mail message.

注目:$message変数はいつでもメールのビューに渡され、埋め込まれます。ですから、この変数を渡す必要はありません。Note: A $message variable is always passed to e-mail views, and allows the inline embedding of attachments. So, it is best to avoid passing a message variable in your view payload.

HTMLビューに加え、プレーンテキストビューを指定することもできます。You may also specify a plain text view to use in addition to an HTML view:

Mail::send(array('html.view', 'text.view'), $data, $callback);

もしくは'html'か'text'をキーに使用し、片方のタイプだけのビューを指定することも可能です。Or, you may specify only one type of view using the html or text keys:

Mail::send(array('text' => 'view'), $data, $callback);

メールにカーボンコピーや添付ファイルなどのオプションも指定できます。You may specify other options on the e-mail message such as any carbon copies or attachments as well:

Mail::send('emails.welcome', $data, function($message)
{
	$message->from('us@example.com', 'Laravel');

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

	$message->attach($pathToFile);
});

添付ファイルをメッセージに付ける場合は、MIMEタイプと表示名のどちらか、もしくは両方を指定することもできます。When attaching files to a message, you may also specify a MIME type and / or a display name:

$message->attach($pathToFile, array('as' => $display, 'mime' => $mime));

注目: Mail::sendクロージャーに渡されるメッセージのインスタンスは、SwiftMailer messageクラスを拡張しています。ですからメッセージを作成するため、このクラスのメソッドを呼び出すこともできます。Note: The message instance passed to a Mail::send Closure extends the SwiftMailer message class, allowing you to call any method on that class to build your e-mail messages.

インラインの埋め込みEmbedding Inline Attachments

メールに画像をインラインで埋め込むことは典型的な厄介者です。しかしLaravelは画像をメールに付け、最適なCIDを得る便利な方法を提供しています。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.

メールのビューに画像を埋め込むEmbedding An Image In An E-Mail View

<body>
	Here is an image:

	<img src="<?php echo $message->embed($pathToFile); ?>">
</body>

メールのビューにロウ(raw)・データーを埋め込むEmbedding Raw Data In An E-Mail View

<body>
	Here is an image from raw data:

	<img src="<?php echo $message->embedData($data, $name); ?>">
</body>

$message変数はいつもMailクラスによりメールビューに渡されることに注目してください。Note that the $message variable is always passed to e-mail views by the Mail class.

キュー使用メールQueueing Mail

メールメッセージをキューイングするQueueing A Mail Message

メール送信はアプリケーションのレスポンスをとても遅くしてしまうため、多くの開発者はメールメッセージをバックグラウンドでキュー送信するようにしています。Laravelでは組み込みの共通キューAPIを使用することで簡単に取り扱えるようになっています。メールメッセージにキューを使用するには、Mailクラスのqueueメソッドをシンプルに使用してください。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 unified queue API[/docs/4.2/queues]. To queue a mail message, simply use the queue method on the Mail class:

Mail::queue('emails.welcome', $data, function($message)
{
	$message->to('foo@example.com', 'John Smith')->subject('Welcome!');
});

もしくはlaterメソッドを使用し、メールを送信するまでの遅延秒数を指定することも可能です。You may also specify the number of seconds you wish to delay the sending of the mail message using the later method:

Mail::later(5, 'emails.welcome', $data, function($message)
{
	$message->to('foo@example.com', 'John Smith')->subject('Welcome!');
});

またメッセージを登録する特定のキューか「チューブ」をqueueOnlaterOnメソッドを使用し、指定することも可能です。If you wish to specify a specific queue or "tube" on which to push the message, you may do so using the queueOn and laterOn methods:

Mail::queueOn('queue-name', 'emails.welcome', $data, function($message)
{
	$message->to('foo@example.com', 'John Smith')->subject('Welcome!');
});

メールとローカル開発Mail & Local Development

メールを送信するアプリケーションを開発する場合、ローカルもしくは開発環境からのメッセージ送信を無効にするほうが好ましいでしょう。そのためには、Mail::pretendメソッドを呼び出すか、app/config/mail.php設定ファイルでpretendオプションをtrueにしてください。pretendモードの場合、受取人に向け送信する代わりに、アプリケーションのログファイルに書き込まれます。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 Mail::pretend method, or set the pretend option in the app/config/mail.php configuration file to true. When the mailer is in pretend mode, messages will be written to your application's log files instead of being sent to the recipient.

メールのPretendモードを有効にする。Enabling Pretend Mail Mode

Mail::pretend();

章選択

Artisan CLI

設定

明暗テーマ
light_mode
dark_mode
brightness_auto システム設定に合わせる
テーマ選択
photo_size_select_actual デフォルト
photo_size_select_actual モノクローム(白黒)
photo_size_select_actual Solarized風
photo_size_select_actual GitHub風(青ベース)
photo_size_select_actual Viva(黄緑ベース)
photo_size_select_actual Happy(紫ベース)
photo_size_select_actual Mint(緑ベース)
コードハイライトテーマ選択

明暗テーマごとに、コードハイライトのテーマを指定できます。

テーマ配色確認
スクリーン表示幅
640px
80%
90%
100%

768px以上の幅があるときのドキュメント部分表示幅です。

インデント
無し
1rem
2rem
3rem
原文確認
原文を全行表示
原文を一行ずつ表示
使用しない

※ 段落末のEボタンへカーソルオンで原文をPopupします。

Diff表示形式
色分けのみで区別
行頭の±で区別
削除線と追記で区別

※ [tl!…]形式の挿入削除行の表示形式です。

Pagination和文
ペジネーション
ペギネーション
ページネーション
ページ付け
Scaffold和文
スカフォールド
スキャフォールド
型枠生成
本文フォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

コードフォント

総称名以外はCSSと同様に、"〜"でエスケープしてください。

保存内容リセット

localStrageに保存してある設定項目をすべて削除し、デフォルト状態へ戻します。

ヘッダー項目移動

キーボード操作