Attaching a file to PHPMailer
Asked Answered
M

1

3

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;
Merkley answered 4/7, 2014 at 19:34 Comment(2)
The most obvious solution is to save the blob to a file.Conchoid
Musa, thanks for the reply, yes, I was thinking: Save the file, attached the file, send the e-mail, then delete the file. However, seems a bit overkill. If there isn't a more straightforward direct solution, thats the one i'll go with.Merkley
D
5

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.
Dysfunction answered 5/7, 2014 at 17:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.