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

时间:2015-08-29 12:16:34

标签: php email phpmailer

我有两个文件:

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

和电子邮件模板.phtml

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

PHPmailer代码:

$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);
        }

我通过PHPmailer发送此电子邮件,但它一直告诉我,电子邮件的正文是空的,但我收到了正确格式化和数据的电子邮件。只是这个错误信息不断出现。如果我改变include_once只是include,它会发送两封电子邮件而不是一封。

我看不出问题出在哪里

感谢您的帮助

编辑:电子邮件附带正常数据,正确格式化,第二次空白......

0 个答案:

没有答案