在 php 中发送 Html 页面作为邮件正文,其中包含变量值
Sending Html page as body of Mail in php with variable values
我在我的服务器上上传了一个 html 页面 payment_receipt.html;
我正在使用 phpmailer 发送电子邮件。这张收据我必须作为电子邮件的正文发送。
简单
$Content = file_get_contents("somefile.html"))
可以做到这一点。
但是我需要设置金额,客户名称等值。
它们被放置在 html 内,如
<div class="customerName">Dear{Customer Name}</div>
<div class="confirmation">This email confirms your purchase of following services:</div>
等等
如何在我的 html 中设置这些值,然后再将其作为邮件正文发送。?
如果您始终知道需要替换的字符串是什么,运行 $Content
上的 str_replace 或类似字符串
$Content = str_replace('{Customer Name}', $replacement_variable, $Content);
你可以像这样使用多个变量
$newText = str_replace(["{Name}", "{Adress}"], ["Charles", "Street X"], $oldText);
我在我的服务器上上传了一个 html 页面 payment_receipt.html;
我正在使用 phpmailer 发送电子邮件。这张收据我必须作为电子邮件的正文发送。
简单
$Content = file_get_contents("somefile.html"))
可以做到这一点。 但是我需要设置金额,客户名称等值。 它们被放置在 html 内,如
<div class="customerName">Dear{Customer Name}</div>
<div class="confirmation">This email confirms your purchase of following services:</div>
等等
如何在我的 html 中设置这些值,然后再将其作为邮件正文发送。?
如果您始终知道需要替换的字符串是什么,运行 $Content
上的 str_replace 或类似字符串$Content = str_replace('{Customer Name}', $replacement_variable, $Content);
你可以像这样使用多个变量
$newText = str_replace(["{Name}", "{Adress}"], ["Charles", "Street X"], $oldText);