我有一个 html 格式的邮件程序模板。它是一个带有内联 css 的大型 html 文件,将保存动态数据。
现在这是我的代码。
$subject = "V-Link Logistics Booking Update";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$msg = "mails/airbill.php";
mail($res['0']['user_email'],$subject,$msg,$headers);
这似乎不起作用,而且确实没有解决问题。任何建议都会非常有帮助。
最佳答案
您可以使用 PHP function file_get_contents()
简单地提取文件的内容。
因此您的 $msg
变量将像这样构建:
$msg = file_get_contents("mails/airbill.php");
如果 airbill.php
需要通过 PHP 解释器传递,您可以使用 include()
函数的返回值(即计算代码)。要使用此方法,airbill.php
文件需要实际将其内容作为字符串返回(使用简单的 return 语句)。所以你可以这样做:
空运单.php :
<?php
$message = <<<message
<strong>This</strong> is the content of the <span style="...">email</span>
message;
return $message;
?>
您的其他文件将如下所示:
$interpreted_content = include("mails/airbill.php")
$msg = $interpreted_content;
关于php mail - 在邮件中包含一个 html 文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18577181/