【问题标题】:PHPMailer include PHP Template returns 1 in the emailPHPMailer 包含 PHP 模板在电子邮件中返回 1
【发布时间】:2014-04-29 04:13:58
【问题描述】:

我在一个电子邮件模板上,该电子邮件模板将是基于动态的。所以我将模板制作为 PHP 文件,并在 PHP 中使用 INCLUDE 函数包含内容。电子邮件通过了,但我在电子邮件中收到 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.");
    }

【问题讨论】:

    标签: php email


    【解决方案1】:

    您需要更改这部分代码

    $mail->MsgHTML($preview_contents);
    

    看起来像这样

    $mail->MsgHTML($content);
    

    我认为这对你有用

    【讨论】:

    • 但是像 'site_url()' 这样的全局 WordPress 变量在 PHP 脚本中仍然不起作用。
    • 对不起,我对wordpress一无所知。是否在脚本中执行其他常规 php 变量和函数。如果是这样,您似乎还没有初始化 wordpress 特定的变量
    猜你喜欢
    • 2015-09-17
    • 2017-07-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多