質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.48%
Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

Q&A

解決済

4回答

641閲覧

パスワード再発行メールにCCを追加する

akihiro0117

総合スコア32

Laravel 5

Laravel 5は、PHPフレームワークLaravelの最新バージョンで、2014年11月に発表予定です。ディレクトリ構造がが現行版より大幅に変更されるほか、メソッドインジェクションやFormRequestの利用が可能になります。

0グッド

0クリップ

投稿2018/01/09 03:14

laravel5を使っています。

use Illuminate\Foundation\Auth\ResetsPasswords;
を利用して、パスワード再発行の処理を実装しています。

お客様宛にメールを送るのと同時に、別のアドレスへCCで送りたいです。
#ユーザーサポートのためです。

Illuminate\Foundation内のソースを見て回っているのですが、メールを送信しているところすら、見つけられず、目的を達成できていません。
もし何かご存じの方がいらっしゃったら、アドバイスいただけないでしょうか?

Illuminate/Auth/Notifications/ResetPasswordとかをオーバーライドして、処理を書き変えるしか方法はないのでしょうか?

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

guest

回答4

0

本題ではありませんが、CCは送信者全員にわかるものですので、お客様の複数アドレスに同時配信という状況なら別ですが、そうでない先に送るのなら「パスワードリセット用のメールが違う場所にも送られている」となって、お客様に不信感を持たれる危険も大きいです。

内部的に必要な控えメールの場合は、BCCにしましょう。

投稿2018/01/09 04:47

maisumakun

総合スコア145184

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

簡単な流れを提示します…
1.下記のコマンドで新しいnotificationを作成します。

php

1 php artisan make:notification passwordReset

2.App\Notificationsに新しいclassが出来ると思います。この中のtoMailメソッドを好きに書き換えてください。
(例)

php

1 /** 2 * Get the mail representation of the notification. 3 * 4 * @param mixed $notifiable 5 * @return \Illuminate\Notifications\Messages\MailMessage 6 */ 7 public function toMail($notifiable) 8 { 9 return (new MailMessage) 10 ->subject('パスワード再設定') 11 ->cc('hogehoge@example.com') 12 //この下はメール文面です。好きに書き換えて下さい。 13 ->view('emails.reset') 14 ->action('再設定用URL', url('/password/reset', $this->token)); 15 }

3.最後にUserモデルでsendPasswordResetNotificationをオーバーライドして下さい。
(例)

<?php namespace App; use Illuminate\Notifications\Notifiable; use Illuminate\Foundation\Auth\User as Authenticatable; use App\Notifications\passwordReset; class User extends Authenticatable { use Notifiable; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'email', 'password', ]; /** * The attributes that should be hidden for arrays. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; // sendPasswordResetNotificationをオーバーライド public function sendPasswordResetNotification($token) { $this->notify(new passwordReset($token)); } }

これで対応は完了です。ちなみに、デフォルトでは下記のメソッドが動いていそうです。

<?php namespace Illuminate\Auth\Notifications; use Illuminate\Notifications\Notification; use Illuminate\Notifications\Messages\MailMessage; class ResetPassword extends Notification { /** * The password reset token. * * @var string */ public $token; /** * Create a notification instance. * * @param string $token * @return void */ public function __construct($token) { $this->token = $token; } /** * Get the notification's channels. * * @param mixed $notifiable * @return array|string */ public function via($notifiable) { return ['mail']; } /** * Build the mail representation of the notification. * * @param mixed $notifiable * @return \Illuminate\Notifications\Messages\MailMessage */ public function toMail($notifiable) { return (new MailMessage) ->line('You are receiving this email because we received a password reset request for your account.') ->action('Reset Password', url(config('app.url').route('password.reset', $this->token, false))) ->line('If you did not request a password reset, no further action is required.'); } }

投稿2018/01/09 04:20

motuo

総合スコア3027

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

パスワードリセットのメールは、ユーザークラスのsendPasswordResetNotificationにより実装されています。
Laravel 5.5 パスワードリセット リセットメールのカスタマイズ
Laravel 5.5 通知

※ メール送信箇所はIlluminate\Auth\Passwords\PasswordBrokerクラスのsendResetLinkメソッド

これを独自のメールにする場合は、独自の通知クラスを作成し、その中でtoMailメソッドを実装して下さい。

#User.php public function sendPasswordResetNotification($token) { $this->notify(new 独自の通知クラス($token)); }
#独自の通知クラスで、toMailの実装 public function toMail($notifiable) { return (new MailMessage) ->subject("xxx) ->cc(ここにcc用のメール定義) ->view("xxx"); }

[追記]
質問の通りの機能ではサービス上の問題の指摘もあるので、akihiro0117さんのシステムの意図次第ですが、単にパスワードリセットを行ったかどうかを運営者が知りたい場合は、
Illuminate\Foundation\Auth\ResetsPasswordsのresetPasswordメソッドで、event(new PasswordReset($user));として、PasswordResetイベントが発行されているので、
これのリスナを作って別にメールを送信すると良いかと思います。
Laravel 5.5 イベント

投稿2018/01/09 04:20

編集2018/01/09 05:09
aro10

総合スコア4106

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

aro10

2018/01/09 04:22

投稿が重複してしまいましたが、motuoさんのコメントと合わせて確認するとできるかと思います。
guest

0

ベストアンサー

larabel の実装を理解していないので、誤った認識の可能性があります

セキュリティ的な観点とメンテナンス性とを鑑みて、CC(BCC) ではなく、別アクションとして実装するほうが良い気がします。

CC したい意図がよく分からないのですが、リマインダーを送った後に、サポート向けに必要な情報を整理してメールすることで、ワンタイム URL を間違って踏むとか、おかしなことをするのを防ぐことが出来ます。

投稿2018/01/09 04:57

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.48%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問