Добавить скрытую копию в почту, когда почта для проверки пользователя или почта для сброса пароля срабатывают в laravel по умолчанию Auth

Я пытаюсь добавить bbc к почтовым сообщениям для проверки и восстановления пароля в системе аутентификации по умолчанию laravel. В системе аутентификации по умолчанию laravel нет почтовой функции, как я могу добавить -›bcc() в проверочную почту и почту для сброса пароля.

Любая помощь будет оценена.

как это

Mail::to($request->user())
->cc($moreUsers)
->bcc('[email protected]')
->send(new OrderShipped($order));

забыл парольcontroller.php

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Password;
use Illuminate\Foundation\Auth\SendsPasswordResetEmails;
use Auth;

class ForgotPasswordController extends Controller
{          
    use SendsPasswordResetEmails;
  
    public function __construct()
    {
        $this->middleware('guest');
    }

    public function sendResetLinkEmail(Request $request)
    {
         $this->validateEmail($request);
         
         $response = $this->broker()->sendResetLink(
             $request->only('email')
         );
         
         return $response == Password::RESET_LINK_SENT
                     ? $this->sendResetLinkResponse($request, $response)
                     : $this->sendResetLinkFailedResponse($request, $response);
    }
}

проверкаконтроллер.php

<?php

namespace App\Http\Controllers\Auth;

use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Illuminate\Foundation\Auth\VerifiesEmails;

class VerificationController extends Controller
{       
    use VerifiesEmails;
        
    protected $redirectTo = 'shop/home';
       
    public function __construct()
    {
        $this->middleware('auth')->only('verify');
        $this->middleware('signed')->only('verify');
        $this->middleware('throttle:6,1')->only('verify', 'resend');
    }
}

person Hemant Kumar    schedule 12.09.2020    source источник


Ответы (2)


php artisan make:notification ResetPassword

затем добавьте этот код в ResetPassword

<?php

namespace App\Notifications;

use Illuminate\Notifications\Messages\MailMessage;
use Illuminate\Notifications\Notification;
use Illuminate\Support\Facades\Lang;

class ResetPassword extends Notification
{
     /**
     * The password reset token.
     *
     * @var string
     */
    public $token;

    /**
     * The callback that should be used to build the mail message.
     *
     * @var \Closure|null
     */
    public static $toMailCallback;

    /**
     * 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)
    {
        if (static::$toMailCallback) {
            return call_user_func(static::$toMailCallback, $notifiable, $this->token);
        }

        return (new MailMessage)        
            ->subject(Lang::get('Reset Password Notification'))
            ->bcc('[email protected]') //add bcc for another email
            ->line(Lang::get('You are receiving this email because we received a password reset request for your account.'))
            ->action(Lang::get('Reset Password'), url(route('password.reset', ['token' => $this->token, 'email' => $notifiable->getEmailForPasswordReset()], false)))
            ->line(Lang::get('This password reset link will expire in :count minutes.', ['count' => config('auth.passwords.'.config('auth.defaults.passwords').'.expire')]))
            ->line(Lang::get('If you did not request a password reset, no further action is required.'));
    }

    /**
     * Set a callback that should be used when building the notification mail message.
     *
     * @param  \Closure  $callback
     * @return void
     */
    public static function toMailUsing($callback)
    {
        static::$toMailCallback = $callback;
    }
}

затем переопределите метод в пользовательском классе

<?php

namespace App;

use App\Helper\Helper;
use App\Notifications\ResetPassword;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;

class User extends Authenticatable
{
    use Notifiable;

    /**
     * The attributes that are mass assignable.
     *
     * @var array
     */
    protected $table = 'users';
    protected $fillable = [
        'name', 'email', 'password',
    ];

    /**
     * The attributes that should be hidden for arrays.
     *
     * @var array
     */
    protected $hidden = [
        'password', 'remember_token',
    ];

    // Override sendPasswordResetNotification
    public function sendPasswordResetNotification($token)
    {
        $this->notify(new ResetPassword($token));
    }


}

и сделайте то же самое с проверкой

Метод переопределения для EmailVerification

   public function sendEmailVerificationNotification()
    {
        $this->notify(new VerifyEmail);
    }
person ahmed nasser    schedule 13.09.2020

Вы также можете прослушивать событие отправки почты, например:

приложение/Провайдеры/EventServiceProvider.php

 /**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
     MessageSending::class => [
         LogOutboundMessages::class
     ]
];

Затем app/Listeners/LogOutboundMessages.php

class LogOutboundMessages
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  object  $event
     * @return void
     */
    public function handle(MessageSending $event)
    {
        $event->message->addBcc('[email protected]');
    }
}
person Zachary Craig    schedule 13.09.2020