简体   繁体   English

通过PHPMailer发送PHP生成的HTML

[英]Sending PHP generated HTML by PHPMailer

I'm trying to setup PHPMailer to send e-mails that consist mostly from PHP generated HTML (ie dynamic tables made with data from a database, inside functions and even different classes). 我正在尝试将PHPMailer设置为发送主要由PHP生成的HTML组成的电子邮件(即,由数据库,内部函数甚至不同类的数据组成的动态表)。 However most examples I've seen only have this method for adding content to the email body: 但是,我见过的大多数示例仅具有将内容添加到电子邮件正文的这种方法:

$mail->Body = $body;

which seems easy to implement for simple content and/or strings but not dynamic PHP content. 对于简单的内容和/或字符串,但对于动态PHP内容,似乎易于实现。

Is there some kind of way of adding content to the e-mail body by chunks or perhaps an entire PHP page? 是否有某种方式可以通过块或整个PHP页面将内容添加到电子邮件正文中? It seems like a really stupid question but I can't quite find a way to do it... 看来这是一个非常愚蠢的问题,但是我找不到解决办法...

You can generate the content and put it in to a buffer string , then, you can set the body of PHPMailer with this. 您可以生成内容并将其放入缓冲区字符串中 ,然后可以使用此设置PHPMailer正文

Here an example: 这里是一个例子:

ob_start();

// Include a file here or insert the code that generate the HTML
// Example
include('page.php');

$body = ob_get_contents();
ob_end_clean();

$mail->Body = $body;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM