简体   繁体   English

Silverstripe 3:将徽标图像添加到自定义电子邮件模板中

[英]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.我有一个自定义电子邮件模板,当用户注册我的 silverstripe 站点时,我将其用作验证电子邮件,但它不会显示图像。

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.发送电子邮件时,我们需要确保所有 URL 都是绝对 URL 而不是相对 URL。

We can do this by using $AbsoluteLink for links and appending $AbsoluteBaseURL to resources.我们可以通过将$AbsoluteLink用于链接并将$AbsoluteBaseURL附加到资源来做到这一点。

In SilverStripe 3 we can do this for a resource with the following:在 SilverStripe 3 中,我们可以通过以下方式对资源执行此操作:

<img src="{$AbsoluteBaseURL}{$ThemeDir}/assets/images/mylogo.png" alt="$SiteConfig.Title" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM