php mail - 在邮件中包含一个 html 文件

标签 php

我有一个 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/

相关文章:

php - 将 CURLOPT_CAINFO 与更新的 CA bundle 一起使用会导致证书验证失败

php - 使用客户端证书进行身份验证

php使用@符号动态调用函数

php - 有没有办法在撤销方法时查看正在执行的代码?

php - 调用未定义函数 session_is_registered()

PHP glob 目录 UTF-8

php - 计算 PHP 中 SQL 表的数量?

php - 如何获取从 file_get_contents() 派生的内容的大小

javascript - 使用 ajax、php 加载更多帖子

php - codeigniter 事件记录左连接