Set styles for dynamically added html code in email template

I am currently working on a flexible email template and am facing a problem how to generate dynamically added html code.

Since most of the email client is not supported by inline CSS, I added inline styles, since the template loading part is dynamically I cannot add inline styles for this part.

Example: I need to load the following html example code dynamically into my email template.

<p>bla bla bla .....</p>
<a href=""><img src="" class="" /></a>
<p>bla bla bla .....</p>

      

In this example, how do I set the max-width

item img

to work for most email clients?

Please note that I am using PHP

as programming language.

Thanks in advance.

+3


source to share


2 answers


I have used html dom parser to make changes to html code as shown below,

function add_inline_styles($string){
    $string = str_get_html($string);
    foreach($string->find('img') as $key => $img_tags) {
        $img_tags->setAttribute("style", max-width: 570px;");
    }
    return $string;
}

      



To use the dom parser, you must include simple_html_dom.php and follow the documentation for more information .

0


source


if you can install class

or src

, you can do:

 $class='something';

 $class= $class. '"' . ' style="max-wdth:100px;';

      



then you will have:

 <img src="" class="something" style="max-wdth:100px;" />

      

0


source







All Articles