[英]Sends email twice on every request (laravel 7.0)
Hello everyone,大家好,
I am using laravel 7.0.我正在使用 laravel 7.0。 I am facing a bug, the email send twice on every request.
我面临一个错误,email 在每个请求上发送两次。 I checked my code again and again but not found any mistake.
我一遍又一遍地检查我的代码,但没有发现任何错误。 below I am adding code
下面我添加代码
here is controller method controller fetches user and sends email这是 controller 方法controller 获取用户并发送 email
public function __invoke(Request $request)
{
try{
$user = User::all()->first();
if($user->language == 'enUS'){
$emailTemplate = email_template::whereType('information_en')->first();
}else if($user->language == 'deDE'){
$emailTemplate = email_template::whereType('information_de')->first();
}
$templateBody = $emailTemplate->body;
$templateBody = str_replace('#Title#', $user->title, $templateBody);
$templateBody = str_replace('#LastName#', $user->lname, $templateBody);
$data = [];
$data['email'] = $user->email;
$data['subject'] = $emailTemplate->subject;
$data['body'] = $templateBody;
Mail::to($user->email)->send(new EmailSenderMail($data));
return "<div>Email has been sent to all user.</div>";
} catch (\Exception $e) {
return $e->getMessage();
}
}
here is mail class这是邮件 class
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class EmailSenderMail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public $data;
public function __construct($data){
$this->data = $data;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
return $this->view('email.EmailSender')
->subject($this->data['subject'])
->with([
'EmailSenderBody' => $this->data['body'],
]);
}
}*
Problem solved.问题解决了。
If I use Redirect statement instead of return statement then my problem is solved如果我使用Redirect语句而不是return语句,那么我的问题就解决了
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.