donglikuang8145 2015-08-29 12:16
浏览 15

使用ob_start()从外部文件获取邮件模板

I have two files:

function emailTemplate() {
        if($this->template) {
            extract($this->email_data);
            ob_start();
                include_once("email_templates/".$this->template.".phtml");
            return ob_get_clean();
        }
}

and email template .phtml

<div>Hello, Your order has been accepted. <?= $some_data ?></div>

PHPmailer code:

$mail = new PHPMailer();
        $mail->SetLanguage("cz");
        $mail->IsSMTP(); 
        $mail->Host = "smtp.some.cz";
        $mail->SMTPAuth = true; 
        $mail->Username = "info@some.cz";
        $mail->Password = "xysdff";
        $mail->From = "info@some.cz";
        $mail->FromName = "Some.cz";    
        $mail->AddAddress($this->xy);
        $mail->AddBCC($this->xy2, 'potvrzení');

        $mail->IsHTML(true);
        $mail->Subject = $subject;

        $mail->Body = $template;

        $mail->AltBody = $template;
        $mail->WordWrap = 50;
        $mail->CharSet = "utf-8";
        }

        if(!$mail->Send()) {
            throw new Exception($mail->ErrorInfo);
        }

I send this email via PHPmailer, but it keep telling me that body of an email is empty but i get the email with right formating and data. Just this error message keep showing up. if i change include_once for just include, it send me two emails instead of one.

I don't see where the problem is

Thanks for help

EDIT: email came with normal data a right formated and second came empty...

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 软件测试决策法疑问求解答
    • ¥15 win11 23H2删除推荐的项目,支持注册表等
    • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
    • ¥15 qt6.6.3 基于百度云的语音识别 不会改
    • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
    • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
    • ¥15 lingo18勾选global solver求解使用的算法
    • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行