首页 > 解决方案 > 包含 HTML 作为字符串的 PHP 变量 - 需要转换为图像或 PDF - 通过电子邮件发送响应

问题描述

我正在发送电子邮件表单 php 代码,一旦发送电子邮件,我的电子邮件正文是 HTML 背景图像未显示在 Outlook 桌面应用程序中,但它在 Outlook Web 邮件中工作正常,如何使其在桌面 Outlook 应用程序中可见

因此,我正在考虑将电子邮件正文转换为 pdf 或图像,以便我可以将其添加为邮件正文

谁能指导我做

$emailBody='<!DOCTYPE html>
<html>
<head>
<title></title>
<style>
#textDiv{
background-image: url("appreciation-'.$imageId.'.jpg");background-repeat: no-repeat;width:595px;height: 842px;color: white;float: center;
}
#p1{
padding-top: 420px;padding-left: 50px;width: 500px;font-size: large;
}
#p2{
padding-top: 30px;padding-left: 50px;width: 500px;font-size: 25px;
}
</style>
</head>
<body>
<center> 
<div id="textDiv"  align="center" style="font-family: cursive; text-align:center;">
    <p id="p1">Hi '.$actReciverName.', you have received Kudos from '.$senderName.' </p>
    <p id="p2"><i><u>"'.$comment.'"</u></i></p> 
</div>
</center>
</body>
</html>'

提前感谢您的支持

标签: phphtmlimagepdfhtml-email

解决方案


在电子邮件正文/模板中添加图像作为背景不是最佳做法,如果需要,这里有一些针对 IE 和 Outlook 的hack,因为这些电子邮件阅读器基于 MS Word,因此有必要在 IE 注释中添加一些 XML 和特殊标签到 HTML代码。

例子:

<div style="background-color:#7bceeb;">
  <!--[if gte mso 9]>
  <v:background xmlns:v="urn:schemas-microsoft-com:vml" fill="t">
    <v:fill type="tile" src="https://i.imgur.com/YJOX1PC.png" color="#7bceeb"/>
  </v:background>
  <![endif]-->
  <table height="100%" width="100%" cellpadding="0" cellspacing="0" border="0">
    <tr>
      <td valign="top" align="left" background="https://i.imgur.com/YJOX1PC.png">

        ... your content here ...

      </td>
    </tr>
  </table>
</div>

注意对于电子邮件,<table>请尽可能多地使用<div>

用作参考:https ://backgrounds.cm/


推荐阅读