3

I have a custom email template which I am using as the validation email when a user signs up to my silverstripe site but it won't display images.

I want to add my logo at the end of the email but it will not render any image, will only load alt text.

My code to send the email:

$email = MemberConfirmationEmail::create($this, $member);
$approve = Controller::join_links(
    Director::baseURL(),
    'member-approval',
    $member->ID,
    '?token=' . $member->ValidationKey
);
$email->setSubject('Registration Account Confirmation'));
$email->setTemplate('CustomMemberConfirmationEmail');
$email->populateTemplate(array('ApproveLink' => Director::absoluteURL($approve)));
$email->send();

This email template has an image tag in it with the image saved at:

themes/mytheme/assets/images/mylogo.png

All of this works perfectly fine except for rendering the image.

Am I missing something or saving it in the wrong place?

subs
  • 179
  • 1
  • 11

1 Answers1

2

When sending an email we need to make sure all our URLs are absolute URLs and not relative URLs.

We can do this by using $AbsoluteLink for links and appending $AbsoluteBaseURL to resources.

In SilverStripe 3 we can do this for a resource with the following:

<img src="{$AbsoluteBaseURL}{$ThemeDir}/assets/images/mylogo.png" alt="$SiteConfig.Title" />
3dgoo
  • 15,716
  • 6
  • 46
  • 58