[英]Sends email twice on every request (laravel 7.0)
大家好,
我正在使用 laravel 7.0。 我面臨一個錯誤,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();
}
}
這是郵件 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'],
]);
}
}*
問題解決了。
如果我使用Redirect語句而不是return語句,那么我的問題就解決了
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.