使用模板的php邮件

使用模板的php邮件,php,Php,可能重复: 我对下面的内容有点困惑 消息警报功能 public static function MsgAlert($email, $name, $subject, $message) { $msg = include('mailer.php'); $subject = 'New Message'; if ($email != '' && validate_email($email)) { $mailer = new PHPMa

可能重复:

我对下面的内容有点困惑

消息警报功能

public static function MsgAlert($email, $name, $subject, $message)
{
    $msg = include('mailer.php');

    $subject = 'New Message';

    if ($email != '' && validate_email($email))
    {
        $mailer = new PHPMailer();

        $mailer->SetFrom(ADMIN_EMAIL, SITE_NAME);
        $mailer->AddAddress($email);
        $mailer->Subject = $subject;
        $mailer->Body = Postman::nl2br($msg);
        $mailer->AltBody = $msg;
        $mailer->Send();
    }
}
我已经把我的时事通讯设计放到mailer.php中,请检查标记

mailer.php

<div>
<h1><?php $subject; ?><span>27 September 2011 at 6:26 pm</span></h1>
<div>
<p>Hello <?php $name; ?>,</p>
<?php $message; ?>
</div> <!--message container -->
</div>

2011年9月27日下午6:26
你好,


我是在使用正确的方法,还是应该做得更好,因为它不起作用。请建议。谢谢。

您不能将其包含到变量中,但您可以使用php实现所需的结果,例如:

ob_start();
include 'mailer.php';
$msg = ob_get_clean();
这将呈现模板并将结果存储在
$msg

include()
不返回所包含的内容。它将返回true表示成功(文件已包含/执行)或false(文件无法包含)。根据您当前的结构,您需要:

ob_start();
include('mailer.php');
$msg = ob_get_clean();

捕获mailer.php脚本的输出(包括在内)。

您好,在我的脑海中看起来像您的(或者反过来说):)是的,在我单击提交时看到了“另一个答案已发布”。+1因为您/我们的答案很棒;)。a+1表示您实际链接到OB文档。感谢您的正确快速回答