Attaching a file to PHPMailer

喜你入骨 提交于 2019-12-11 03:28:12

问题


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;

回答1:


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.


来源:https://stackoverflow.com/questions/24580014/attaching-a-file-to-phpmailer

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!