简体   繁体   中英

echo background-image

I am trying echo a background-image inside a .phtml to send an email.

However i am having troubles with the quotes. The image is not shown.

<?php echo '
    Plataforma <a href="http://xxxx.com/">http://xxxx.com/</a>
    <br>
    <div style="width:220px; height:30px; background-color:black; background-repeat: no-repeat; background-image:url("http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg")"></div>
'
?>

The IDE validate this code as correct, but the image is not shown in the email that is sent.

<?php echo '
    Plataforma <a $href="http://xxxx.com/">http://xxxx.com/</a>
    <br>
    <div $style="width:220px; height:30px; background-color:black; background-repeat: no-repeat; background-image:url(\"http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg\")"></div>
    '
?>

Value of style attribute is enclosed by double quotes, so any double quota inside must be escaped.

You need to change this:

background-image:url("http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg")

to:

background-image:url('http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg')

The double quotes are cutting off your DOM in the wrong place, causing it to mis-read.

Your CSS is invalid. Change this line:

background-image:url("http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg")

to read like this:

background-image:url('http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg')

Because it's inside a style="" attribute, the " symbols in the background-image line are signalling the end of the style attribute instead of the path for your image.

Try using single escaped quotes, like this in URL of image:

<?php echo '
    Plataforma <a href="http://xxxx.com/">http://xxxx.com/</a>
    <br>
    <div style="width:220px; height:30px; background-color:black; background-repeat: no-repeat; background-image:url(\'http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg\')"></div>
'
?>

None of the other answers fixed the problem (gmail, hotmail). This will work

<?php echo '
    Plataforma <a href="http://xxxx.com/">http://xxxx.com/</a>
    <br>
    <div style="width:220px; height:30px; background-color:black;">
        <img src="http://www.inova-ria.pt/images/UebeImg/Thumb/Img_153_363_T.jpg">
    </div>
    '; ?>

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