我正尝试将验证电子邮件发送到注册客户的电子邮件地址,但这是给我的错误消息而不是发送通知电子邮件。
任何帮助都太棒了!在这里苦苦挣扎,不了解对象在哪里,并且错误无济于事。
我做了一些处理,发现问题出在发送邮件的mailable的build方法中。电子邮件发送,URL正确且帐户验证,但是在发送电子邮件时出现此错误,这使我无法在新用户注册后重定向到确认或登录页面。 / p>
谢谢:)
创建用户:
$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
]);
}
}
答案 0 :(得分:0)
似乎laravel无法找到要在端点中重定向的视图文件。
“登录名/客户”。
答案 1 :(得分:0)
在通知 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.