简体   繁体   English

如何使用从PHP中DB获取的内容将HTML文件附加到电子邮件?

[英]How to attach HTML file to email using content taken from DB in PHP?

How do I send mail via PHP with attachment of HTML file? 如何通过带有HTML文件附件的PHP发送邮件? -> Content of HTML file (code) is in string in DB. -> HTML文件(代码)的内容在DB中以字符串形式存在。 Is there some easy way or free script to do this? 有一些简单的方法或免费脚本可以做到这一点吗? I don't want to store the file localy, I need to read it out of DB and send it straightaway as attachment (not included in body). 我不想在本地存储文件,我需要从数据库中读取文件并将其作为附件直接发送(不包含在主体中)。

如果您很难正确设置标题,则可以始终使用PHP Mailer之类的东西,而不必重新发明轮子。

I like pear. 我喜欢梨。

<?
include('Mail.php');
include('Mail/mime.php');
$text = 'Text version of email';
$html = '<html><body>HTML version of email</body></html>';
$file = './files/example.zip';
$crlf = "rn";
$hdrs = array(
              'From'    => 'someone@domain.pl',
              'To'      => 'someone@domain.pl',
              'Subject' => 'Test mime message'
              );
$mime = new Mail_mime($crlf);
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
$mime->addAttachment($file,'application/octet-stream');
$body = $mime->get();
$hdrs = $mime->headers($hdrs);
$mail =& Mail::factory('mail', $params);
$mail->send('mail@domain.pl', $hdrs, $body); 
?>

You should be able to follow these instructions on sending email attachments. 您应该能够按照以下说明发送电子邮件附件。 You will simply need to adjust your code to read a string from the database instead of reading the contents of a file. 您只需要调整代码即可从数据库读取字符串,而不是读取文件的内容。

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

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