简体   繁体   English

图片未显示在队列中的邮件中 - laravel

[英]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.您必须为您的应用程序设置一个 URL 以便控制台命令知道什么 URL 用于您的应用程序 URL 没有将信息传递给它的网络服务器生成请求。

You can set APP_URL in your .env file for this.为此,您可以在.env文件中设置APP_URL

APP_URL=https://app.site_domain.com

By default it is set to http://localhost , which is why that is showing up.默认情况下,它设置为http://localhost ,这就是显示的原因。

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 文档 - 配置 - 配置缓存

Laravel 6.x Docs - Queues - Queue Workers & Deployment Laravel 6.x 文档 - 队列 - 队列工作者和部署

Use public_path() in place of url() or assets() .使用public_path()代替url()assets() public_path() is working for me. public_path()正在为我工作。

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') }}尝试像这样使用url助手: {{ url('/images/logo.png') }}

  • have you set your APP_URL in.env file你有没有在.env 文件中设置你的 APP_URL
  • you should use <img src="{{ $message->embed($pathToImage) }}"> instead of URL你应该使用<img src="{{ $message->embed($pathToImage) }}">而不是 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.如果您在队列工作程序运行时已将 .env 从 localhost 更新为 app.site_domain.com,您可能需要重新启动主管/工作人员队列。 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.现在您可以在 email 上获取此图像。 You can check this by using an image.您可以使用图像进行检查。 or try using embed($pathToImage) }}">或尝试使用 embed($pathToImage) }}">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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