简体   繁体   中英

image not displaying in mail in queue - laravel

In my mail template I used image path as below:

<img src="{{ URL::to('/images/logo.png') }}" alt="logo" download="false" style="width:50%">

It is working with normal mail (without the queue) but not in mail in queue.

By inspecting element in mail i found that when for normal mail image path is as below:

https://app.site_domain.com/images/logo.png //as expected 

But for mail queue it is:

http://localhost/images/logo.png

You have to set a URL for your application for the Console commands to know what URL to use for your application for URL generation as there is no webserver passing the request information to it.

You can set APP_URL in your .env file for this.

APP_URL=https://app.site_domain.com

By default it is set to http://localhost , which is why that is showing up.

If your configuration is cached you will need to clear it or cache it again:

php artisan config:cache 

You will need to stop the queue workers most likely, (command to make the queue workers die after processing any current jobs):

php artisan queue:restart

Then you can start them up again, or hopefully you have something monitoring those processes and will restart them after they die.

Laravel 6.x Docs - Configuration - Configuration Caching

Laravel 6.x Docs - Queues - Queue Workers & Deployment

Use public_path() in place of url() or assets() . public_path() is working for me.

Try. asset()

<img src="{{ asset('images/logo.png') }}" alt="logo" download="false" style="width:50%">

Try to use url helper like this: {{ url('/images/logo.png') }}

  • have you set your APP_URL in.env file
  • you should use <img src="{{ $message->embed($pathToImage) }}"> instead of URL

Provided that you've updated.env from localhost to app.site_domain.com while queue worker was running, you might want to restart supervisor / worker queues. Clearing and re-caching config will not update the settings in supervisor (that is, of course, if you are using supervisor to manage queues).

You not get image from local.You should upload this image on server.Then give that server image link. Now you can get this image on email. You can check this by using an image. or try using embed($pathToImage) }}">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM