5

I have included all Bootstrap 3 CSS files and other project related JS and CSS files with unique folder names inside the public folder. Here's an example of the structure:

public/pnotify
public/bower_components/bootstrap
public/ckeditor

I have included all these JS and CSS links with exact path on main template and everything loads correctly through out the project, but when I give a Blade file as view for Laravel 5 mail. The CSS doesn't load and everything is messed up in the received email, while the same Blade file is rendered accurately within project. Is it because I haven't implemented asset management of Laravel and mail system of Laravel loads CSS only from assets or I am missing something? Please some one clarify.

3 Answers 3

8

You can link external CSS files in an email, but most likely they will be blocked by the email clients for security reasons. So you'll need to inline the CSS inside your email templates for them to work.

You can try using the following package to help make it easier:

Laravel Mail CSS Inliner

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

3 Comments

does this Inliner works perfectly or there are some other working alternatives too?I seriously need to make my mail view correctly rendered in every mail for my project!.Linking external CSS in mail view is same as linking external CSS files in blade or procedure is different?In github page of 'Laravel Mail CSS Inliner' it has given example for Inining CSS that are in same page within '<style>' tags,does this inliner work for external CSS too?
This works well as far as I've tested it, especially because the integration with Laravel is seamless. It does however have the drawback of needing to place the CSS in <style> tags inside the view itself (so no outside linking). There are alternatives that allow external CSS linked files such as InlineStyle but you have to apply it to the email body before sending (I have not tested this package myself so I can't say how well it works).
Side note: Having emails render exactly the same in all clients is more of an art than an exact science, because email clients are not browsers and they have many restrictions that may alter the way your email is rendered. So just using the CSS you use for your website for an email is not a solution in itself, you need to fine tune and test you emails in multiple clients to be sure they work as expected. Tools like Litmus can help with that process, but they're not very cheap.
3

Change the following:

return $this->subject('new message')->view('layouts.mail.bussiness_partner')->with('data',$this->data);

to this:

return $this->subject('new message')->markdown('layouts.mail.bussiness_partner')->with('data',$this->data);

use markdown then it supports bootstrap

Comments

0

I've come across this question whilst searching for a CSS inliner myself. Laravel Mail CSS Inliner seems to work better with Laravel 5 and above. I am currently using it with 5.2 and it's great.

Comments

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.