php - 将 PHP 变量传递给 html 电子邮件

标签 php html css

我正在使用与 html 混合的内联 css 向我的用户发送 html 邮件。 我遇到的问题是如何将我的变量从我的 php 传递到我的 html 并在我将其作为电子邮件发送时相应地在那里使用它。例如,邮件中包含用户全名、用户购买和购买金额。我如何将它传递给我的 html

 $mail = new PHPMailer;

 $mail->From = "mail@mail.com";
 $mail->FromName = "mail.com";
 $mail->addAddress($email);
 $mail->addReplyTo("mail@mail.com", "Reply");
 $mail->isHTML(true);

 $mail->Subject = "Details";
 $mail->Body = file_get_contents('epay.html');
 $mail->Send();

最佳答案

我建议您使用像 smarty ( http://www.smarty.net/ ) 这样的模板引擎。这是一个示例(作为使用示例从他们的文档中复制粘贴):

从 PHP 分配的变量

通过在它们前面加上美元 ($) 符号来引用的赋值变量。

示例 4.2。赋值变量

<?php

$smarty = new Smarty();

$smarty->assign('firstname', 'Doug');
$smarty->assign('lastname', 'Evans');
$smarty->assign('meetingPlace', 'New York');

$smarty->display('index.tpl');

?>

index.tpl 来源:

Hello {$firstname} {$lastname}, glad to see you can make it.
<br />
{* this will not work as $variables are case sensitive *}
This weeks meeting is in {$meetingplace}.
{* this will work *}
This weeks meeting is in {$meetingPlace}.

以上将输出:

Hello Doug Evans, glad to see you can make it.
<br />
This weeks meeting is in .
This weeks meeting is in New York.

继续阅读此处 http://www.smarty.net/docs/en/language.variables.tpl

关于php - 将 PHP 变量传递给 html 电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44774326/

相关文章:

php - UTF-8 字符未作为 UTF-8 从 PHP 插入到 MySQL 表中

php - 第 17 行出现 fatal error : Call to a member function fetch_assoc() on a non-object in . ..

php - 响应式网站中的 Paypal 集成

html - 如何去除div元素之间的空白

php - mysql pdo 命中计数器

javascript - 使用正则表达式删除前导空格、回车符和不需要的标签

html - 从模板中引用 html 标签

javascript - 我可以找到 window.onclick() 函数何时被覆盖吗?

html - ShinyUI - 如何在流体行/列网格中添加垂直/水平线?

未应用 CSS,样式显示为空白?