1

I have a strange issue with embedding image in job queue.
I am using WAMP for development. Folder structure for my project is C:\wamp\MyProject & the public directory is at C:\wamp\www\app

Mail::send('emails.mailtemplate_rule', ['body' => $data['body']], function ($message) use ($data) {
    $message->to($data['to']);
    $message->from($data['from'], $data['namefrom']);
    $message->subject($data['subject']);
});

<img src="{{ $message->embed('assets/images/logo.png')}}" alt='MyProject' data-default="placeholder" data-max-width="300">

This is working fine when I run this but when I change the driver from 'sync' to 'database' and update the mail function as below:

Mail::queue('emails.mailtemplate_template', ['body' => $data['body']], function ($message) use ($data) {
    $message->to($data['to']);
    $message->from($data['from'], $data['namefrom']);
    $message->subject($data['subject']);
});

When I run the above, I can see the data entry in my jobs table. but when I execute the command: php artisan queue:work It throws as exception which is

[Error Exception]
fopen(assets/images/logo.png): failed to open stream: No such file or directory

If I remove the image it works as a charm. Now I am wondering that why it is not able to find the image while without using job queue it can find the image & embed it into the mail. It should work as desired.
Any help to this, will be appreciated.

2

1 Answer 1

2

change

<img src="{{ $message->embed('assets/images/logo.png')}}" alt='MyProject' data-default="placeholder" data-max-width="300">

to

<img src="{{ $message->embed(asset('images/logo.png'))}}" alt='MyProject' data-default="placeholder" data-max-width="300">

asset() is one of the helper class of laravel. Official Documentation

it will work fine..

Sign up to request clarification or add additional context in comments.

3 Comments

Worked well for me. Thanks
I have been working with laravel for over an year but still there are somethings I haven't seen so far. Thanks again @Jaimin
I guess asset() turns the relative path into an absolute one, right ? You can learn about failed to open stream problems here : stackoverflow.com/questions/36577020/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.