将文件附加到PHPMailer [英] Attaching a file to PHPMailer

查看:79
本文介绍了将文件附加到PHPMailer的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在从事一个项目,该项目具有以blob形式存储在数据库中的文件.我需要将文件附加到电子邮件,然后通过PHPMailer发送出去.我对$mail->addAttachment()很熟悉,但是,此功能似乎仅采用一个文件路径,而我没有.我想知道是否有任何方法可以操纵Blob并提供给该函数?

I am currently working on a project that has files stored in a DB as blobs. I need to attach the file to an e-mail and send it out via PHPMailer. I am familiar with $mail->addAttachment(), however, this function seems to take in a file path only, which I don't have. I was wondering if there is any way to manipulate the blob and feed to this function ?

感谢您的任何建议,谢谢!

I appreciate any suggestions, thanks in advance!

以下代码成功创建了我需要附加的文件的另存为"对话框:

The following successfully creates a 'Save As' dialog of the file I need to attach:

header("Content-disposition: attachment; filename={$filename}.{$file_ext}");
header("Content-type: application/octet-stream");
echo $pdf['data'];
exit;

推荐答案

The addStringAttachment method is capable of handling such case. According to its doc:

* Add a string or binary attachment (non-filesystem).
* This method can be used to attach ascii or binary data,
* such as a BLOB record from a database.

这篇关于将文件附加到PHPMailer的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆