【问题标题】:Laravel - Trying to get property 'view' of non-object, when sending mailLaravel - 发送邮件时尝试获取非对象的属性“视图”
【发布时间】:2020-03-04 19:51:00
【问题描述】:

我正在尝试向注册客户的电子邮件地址发送验证电子邮件,但它给了我有问题的错误,而不是发送通知电子邮件。 任何帮助都会很棒!在这里苦苦挣扎,不明白对象在哪里,报错无用af。
我做了一些死和转储,发现问题出在发送电子邮件的可邮寄邮件的构建方法中。电子邮件已发送,网址正确,并且帐户已验证,但是在发送电子邮件的过程中出现此错误,这使我无法在新用户注册后重定向到确认或登录页面。

谢谢你:)

创建用户:

$validator = Validator::make($request->all(), [
    'name'     => ['required', 'alpha_dash', 'string', 'max:25', 'unique:customers'],
    'email'    => ['required', 'string', 'email', 'max:255', 'unique:customers'],
    'password' => ['required', 'string', 'min:6', 'confirmed'],
]);

if ( $validator->fails() ) {
    $messages = $validator->messages();
    return Redirect::back()->withErrors($validator)->withInput();
    foreach($errors->all() as $error) {
        echo $error;
    }
} elseif ( $validator->passes() ) {
    $customer = customer::create([
        'name' => $request['name'],
        'email' => $request['email'],
        'password' => Hash::make($request['password']),
        'VerifyToken' => Str::random(40),
    ]);

    $customer->SendEmailVerificationNotification();

    return redirect()->intended('login/customer');
}

SendEmailVerificationNotifaction:

public function toMail($notifiable)
{
    $verificationUrl = $this->verificationUrl($notifiable);

    if (static::$toMailCallback) {
        return call_user_func(static::$toMailCallback, $notifiable, $verificationUrl);
    }

    Mail::to($notifiable->email)->send(new validate_email($notifiable->email));
}

validate_email mailable:

    namespace App\Mail;

    use Illuminate\Support\Facades\URL;
    use Illuminate\Bus\Queueable;
    use Illuminate\Mail\Mailable;
    use Illuminate\Queue\SerializesModels;
    use Illuminate\Contracts\Queue\ShouldQueue;

    class validate_email extends Mailable
    {
        use Queueable, SerializesModels;


        public function __construct($data)
        {
            $this->email = $data;
        }

        public function build()
        {
             $url = URL::temporarySignedRoute(
             'verifyCustomer', now()->addMinutes(100),['email'=>$this->email]
            );


            return $this->from('support@xxxx.com')
                        ->view('auth.mail.validate_email')->with([
                            'url' => $url,
                            'email' => $this->email
                        ]);
        }
    }



【问题讨论】:

  • 请出示您的validate_email mailable

标签: php laravel validation email email-verification


【解决方案1】:

似乎 laravel 找不到您试图在端点中重定向的视图文件。

“登录/客户”。

【讨论】:

    【解决方案2】:

    在通知toMail 方法中,您传递到电子邮件模板的数据可能有一些错误。要调试问题,请使用 try catch 块包装在侦听器中调用通知的方法,并将$ex->getMessage()$ex->getTraceAsString() 打印到日志中,这将帮助您找到问题的根本原因错误。

    例如, 在 SendOrderEmailListener 中,执行如下操作,

    <?php
    class SendOrderEmailListener {
    try{ 
        $event->order->customer->notify(new OrderNotification($event->order, $someTemplate);
    }catch(\Exception $ex) {
        \Log::debug($ex->getMessage());
        \Log::debug($ex->getTraceAsString());
    }
    `
    For the curious, the exception trying to get view from non object is thrown from the `Illuminate\Notifications\Channels\MailChannel` -> `send()` -> `buildView()` method.
    

    【讨论】:

      猜你喜欢
      • 2021-06-26
      • 2015-06-12
      • 1970-01-01
      • 2015-09-22
      • 2017-03-20
      • 2014-03-25
      • 2015-01-25
      • 2014-06-23
      相关资源
      最近更新 更多