好的,所以我遇到了一個復雜的問題,我似乎無法在網上找到任何解決方案。
簡單地說,我有一個帶有嵌入圖片的 twig 檔案Branding,它的使用方式如下:
<img src="cid:Branding" alt='branding' />
該“品牌”圖片沒有固定地址,并在創建電子郵件時傳遞給 twig 檔案,其embed()功能如下:
$email = (new Email())
->from(...)
->to(...)
->subject(...)
->embed($branding['content'], 'Branding', $branding['mimeType'])
上面的部分有效。“品牌”影像通過 twig 檔案顯示,一切正常。
現在,我還需要在用于頁腳的模板中使用此影像。我的問題如下:
當我使用這個時:
{% include 'email/footer.html.twig' with {'Branding': Branding} %}
我收到一條錯誤訊息,說它不知道“品牌”變數
當我使用這個時:
{% include 'email/footer.html.twig' with {'Branding': cid:Branding} %}
我收到一條錯誤訊息,說它無法決議“:”字符。
我也考慮嘗試為影像設定一個變數,但我得到了相同的決議錯誤。
{% set Branding = cid:Branding %}
{% include 'email/footer.html.twig' with {'Branding': Branding} %}
我什至不確定我想做的事情是否可行(在這種情況下,你會建議其他什么嗎?)。關于包括的樹枝檔案僅涵蓋文本變數作為示例,因此它對我正在嘗試做的事情不是很有用。
uj5u.com熱心網友回復:
好的,所以這不完全是我正在尋找的解決方案,但我設法通過從 php 檔案中匯入兩次影像來使其作業。
注意:從同一個影像中嵌入兩次對我來說不起作用,并且使兩個影像都無法顯示
$email = (new Email())
->from(...)
->to(...)
->subject(...)
->embed($branding['content'], 'branding', $branding['mimeType'])
->embed($branding['content'], 'brandingFooter', $branding['mimeType'])
我設法通過從兩個不同的地方匯入影像來使其作業,如下所示:
$email = (new Email())
->from(...)
->to(...)
->subject(...)
->embed($branding['content'], 'branding', $branding['mimeType'])
->embedFromPath("{$this->projectDirectory}/media/logo.png", 'footerBranding')
我仍然不明白為什么我不能在同一封電子郵件中兩次使用同一張圖片,但我設法得到了一個解決方案,所以我將其標記為答案。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/521209.html
標籤:phphtml交响乐枝条
