# Image inside a mail-body

**URL:** <https://discourse.cakephp.org/t/image-inside-a-mail-body/12470>\
**Category:** Need Help\
**Created:** [March 7, 2025, 12:48pm UTC](https://discourse.cakephp.org/t/image-inside-a-mail-body/12470 "2025-03-07T12:48:12Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Klaus](https://yyz1.discourse-cdn.com/flex029/user_avatar/discourse.cakephp.org/klaus/32/269_2.png) [@Klaus](https://discourse.cakephp.org/u/Klaus)\
**Post date:** [March 7, 2025, 12:48pm UTC](https://discourse.cakephp.org/t/image-inside-a-mail-body/12470/1 "2025-03-07T12:48:12Z")

</div>

Hi all,  
I am developing a newsletter. There are some elements included with picture an text. It is running well except including the image. I have tried the code below. The path ist correct.  
Addtional I have tried to use WWW\_ROOT instead of $SERVER\_NAME.  
Any tipps??

```
    foreach ($elements as $element) {
        $message .= '<div class="body_element">';
        $message .= '<h4>';
        $message .= $element->title;
        $message .= '</h4>';
        $message .= '<div class = "element_body" > ';

        $picture = 'https://' . $_SERVER['SERVER_NAME'].'/img/' . $element->path . '/' . $element->image;
        $this->log($picture);  
        $link = '<tr><td align="left" style="background-image:url('.$picture.')"></td>';    
        $this->log($link); 
        $message .= $link; 
        $message .= '<td style="font-size:0.9em;">';
        $message .= $element->text;
        $message .= '</td></tr>';
        $message .= '</div>';
        $message .= '</div> ';
        $message .= '<hr>';
    }

```

---

<div class="post-metadata">

**Author:** ![shadowx.jb](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@shadowx.jb](https://discourse.cakephp.org/u/shadowx.jb)\
**Post date:** [March 9, 2025, 4:46pm UTC](https://discourse.cakephp.org/t/image-inside-a-mail-body/12470/2 "2025-03-09T16:46:42Z")

</div>

Replace :

```auto
https://' . $_SERVER['SERVER_NAME']

```

to

```auto
<?php echo Router::fullBaseUrl(); ?>

```
