简体   繁体   中英

Silverstripe 3: Add logo image into custom email template

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?

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" />

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