【问题标题】:Laravel password reset "No Sender"Laravel 密码重置“无发件人”
【发布时间】:2016-07-23 01:56:30
【问题描述】:

当我在 Laravel 5.1 中重置密码时,我收到了电子邮件,但标题中显示“No Sender”。

有没有办法从某个地方为密码重置电子邮件指定发件人?除了发件人,我认为 Laravel 应该自动使用配置文件中指定的电子邮件设置?这很奇怪,因为当我将 Laravel 邮件配置设置为使用“邮件”驱动程序时,我收到退回的电子邮件,说我无法从动态地址发送(这在开发人员中是预期的),但密码重置电子邮件仍然通过.电子邮件重置不应该使用相同的配置设置吗?

【问题讨论】:

    标签: email laravel


    【解决方案1】:

    Jack,您可以在config/mail.php 中为email idname 设置From 属性。我也遇到了同样的问题,刚刚解决了,就像我上面提到的那样。

    【讨论】:

    • 谢谢!最后,这是让 AWS SES 在 L5.6 上运行的最后一步
    【解决方案2】:

    @SeriousJelly Laravel 5.2 的答案更新

    在你的 Auth PasswordController Override resetEmailBuilder 方法中

    class PasswordController extends Controller
    {
        protected function resetEmailBuilder()
        {
            return function (Message $message) {
                $message->subject($this->getEmailSubject());
                $message->from('you@email.com', 'you');
            };
        }
    }
    

    这可能对某人有帮助

    【讨论】:

      【解决方案3】:

      所以,Alexey Mezenin 的答案几乎就在那里,但是,一个很大的不可以覆盖核心文件,因为任何未来的更新都可能破坏功能。

      由于您的PasswordController 应该使用ResetsPassword 特征,您应该能够覆盖PasswordControllerResetsPassword 特征中的任何方法。

      例如,将您自己的 fromsubject 行添加到电子邮件中是一个简单的案例,即在您的 trait 中找到相关函数,复制并粘贴到您的 PasswordController 中并对其进行修改。

      这是一个示例 PasswordController,其中一个函数覆盖了 sendResetLinkEmail() 函数。

      <?php
      
      namespace App\Http\Controllers\Auth;
      
      use Illuminate\Http\Request;
      use Illuminate\Mail\Message;
      use Illuminate\Support\Facades\Password;
      use App\Http\Controllers\Controller;
      use Illuminate\Foundation\Auth\ResetsPasswords;
      
      class PasswordController extends Controller
      {
          /*
          |--------------------------------------------------------------------------
          | Password Reset Controller
          |--------------------------------------------------------------------------
          |
          | This controller is responsible for handling password reset requests
          | and uses a simple trait to include this behavior. You're free to
          | explore this trait and override any methods you wish to tweak.
          |
          */
      
          use ResetsPasswords;
      
          /**
           * Create a new password controller instance.
           *
           * @return void
           */
          public function __construct()
          {
              $this->middleware('guest');
          }
      
          /**
           * Send a reset link to the given user.
           *
           * @param  \Illuminate\Http\Request  $request
           * @return \Illuminate\Http\Response
           */
          public function sendResetLinkEmail(Request $request)
          {
      
              $this->validate($request, ['email' => 'required|email']);
      
              $broker = $this->getBroker();
      
              $response = Password::broker($broker)->sendResetLink($request->only('email'), function (Message $message) {
                  $message->subject($this->getEmailSubject());
                  $message->from(env('MAIL_FROM'), env('APP_NAME'));
              });
      
              switch ($response) {
                  case Password::RESET_LINK_SENT:
                      return $this->getSendResetLinkEmailSuccessResponse($response);
      
                  case Password::INVALID_USER:
                  default:
                      return $this->getSendResetLinkEmailFailureResponse($response);
              }
          }
      

      【讨论】:

      • @Rajkumar 有更好的答案。
      • @ChrisBratherton 如何在“login.blade”中使用“sendResetLinkEmail”
      【解决方案4】:

      也许有更好的解决方案,但您可以手动将代码添加到\vendor\laravel\framework\src\Illuminate\Foundation\Auth\ResetPasswords.php,在此行之后:

      $message->subject($this->getEmailSubject()); // this is line 66
      

      添加如下内容:

      $message->from('my@email.com', 'My Site');
      

      https://laravel.com/docs/5.1/mail#sending-mail

      【讨论】:

        猜你喜欢
        • 2018-06-04
        • 1970-01-01
        • 1970-01-01
        • 2017-09-28
        • 2017-08-31
        • 1970-01-01
        • 1970-01-01
        • 2016-03-01
        • 1970-01-01
        相关资源
        最近更新 更多