我向用戶發送了一封電子郵件以驗證,通過在注冊后使用佇列作業,作業成功運行,但是發送給用戶的(刀片頁面)不顯示影像,盡管如果我發送刀片頁面而不發送它排隊作業,影像看起來很好!?
所以問題是:
- 用戶電子郵件收件箱中刀片頁面中的影像,如果我使用佇列作業發送,則不會出現,雖然如果我直接發送而不使用佇列作業,它看起來很好。
image'URL 如果我使用佇列作業發送它:
http://localhost/assets/img/logo.png

如果我在不使用佇列作業的情況下發送影像'URL:
http://localhost:8000/assets/img/logo.png

刀片頁面
<!doctype html>
<html lang="en"><head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link rel="stylesheet" href="{{asset('assets/css/bootstrap.css')}}">
<style type="text/css">
@import url({{asset('assets/css/style.css')}});
body {
}
</style>
<title>login Page</title>
</head>
<body>
<section class="row">
<div class="col col-sm ">
</div>
<div class="col col-sm ml-5 pl-5" id="col1" >
<div class="container">
<div class="row mt-5 pl-5 mb-5 pb-5">
<img src="{{asset('assets/img/logo.png')}}" width="80" height="80" alt="如果使用佇列作業 Laravel 將影像發送到電子郵件,影像不會出現在刀片頁面中?"/>
</div>
<div hljs-number">5 mb-5 pb-5 ">
<img src="{{asset('assets/img/Sign in ~ Register Illustration.png')}}" width="263" height="241" alt="如果使用佇列作業 Laravel 將影像發送到電子郵件,影像不會出現在刀片頁面中?"/>
</div>
<h1>Hello, </h1>
<h2>Verification Code </h2>
<div hljs-number">5 mb-5 pb-5 pr-5">
<p hljs-number">18 line-spacing-33 font-family-cairo text-muted" id="text1">1Me will Keep your Contacts Secured in our Data base</p>
</div>
</div>
</div>
</section>
<script src="{{asset('js/bootstrap.js')}}"></script>
</body>
</html>
路線:
Route::group(['middleware'=>'guest:web'], function(){
Route::get('/register', [registerController::class,'register'])->name('site.register');
Route::match(['get','post'],'/register-create', [registerController::class,'create'])->name('site.register.create');
});
控制器:
public function create(RegisterRequest $request)
{
$user = User::create([
'firstName' => $request->firstName,
'middleName' => $request->middleName,
'lastName' => $request->lastName,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
$on = \Carbon\Carbon::now()->addSecond(10);
dispatch(new VerifyEmailJob($user))->delay($on);
return redirect()->route('landingPage')->with(['success'=>'We sent verifying email check it']);
}
排隊作業:
<?php
namespace App\Jobs;
use App\Mail\VerifyEmail;
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Queue\SerializesModels;
use Illuminate\Support\Facades\Mail;
class VerifyEmailJob implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
/**
* Create a new job instance.
*
* @return void
*/
public $user;
public function __construct($user)
{
$this->user= $user;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
Mail::to($this->user->email)->send(new VerifyEmail($this->user));
}
}
郵件類:
<?php
namespace App\Mail;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
class VerifyEmail extends Mailable
{
use Queueable, SerializesModels;
/**
* Create a new message instance.
*
* @return void
*/
public $user;
public function __construct($user)
{
$this->user = $user;
}
/**
* Build the message.
*
* @return $this
*/
public function build()
{
$user = $this->user;
return $this->subject('Mail from Oneme')
->view('site.auth.verifyEmail',compact('user'));
}
}
任何幫助
uj5u.com熱心網友回復:
我以前遇到過這個問題。對于電子郵件,所有路徑都必須是完全限定的 URL。因為佇列作業無法巧妙地確定應用程式的基本 url 應該是什么。
https://example.com/static/logo.png是完全限定的 URL,但/static/logo.png不是。為此,我使用了一個APP_URLenv 鍵。
當在沒有 http 請求的情況下執行操作時(如在佇列系統中),laravel 無法轉換/static/logo.png為https://example.com/static/logo.png
在.env檔案上我會做類似的事情
APP_URL = "https://example.com" #change this with your application url
在視圖檔案上,我會做類似的事情
<img src={{ env('APP_URL') . '/static/logo.png' }} />
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/412345.html
標籤:
