PHPMailer包含电子邮件中的PHP模板返回1

时间:2014-04-29 04:13:59

标签: php email

我正在使用电子邮件模板,其中电子邮件模板将基于动态。因此,我正在使用PHP中的INCLUDE函数将模板设为PHP文件并包含内容。电子邮件将通过,但我在电子邮件中收到1。

PHP

ob_start();
$preview_contents = include( get_template_directory() . '/framework/newsletters/includes/preview.php' );
$content = ob_get_contents();
ob_end_clean();

PHPMailer的

    $mail = new PHPMailer();
    $mail->IsSMTP();
    $mail->IsHTML(true);
    $mail->SMTPAuth   = true;
    $mail->Host       = $host;
    $mail->Username   = $username;
    $mail->Password   = $pass;
    $mail->SetFrom("no-reply@xxxxx.com", "Pacific xx");
    $mail->AddAddress($subscribers_preview_email);
    $mail->Subject = $subscribers_subject;
    $mail->MsgHTML($preview_contents);
    if($mail->Send()){
        die("1 | An preview email has been sent to you.");
    } else {
        die("0 | There was an error, please try again later.");
    }

1 个答案:

答案 0 :(得分:1)

您需要更改代码的这一部分

$mail->MsgHTML($preview_contents);

看起来像这样

$mail->MsgHTML($content);

我认为这对你有用