gpt4 book ai didi

php - 在 PHP 中,如何从 mysql 数据库中检索文件并作为电子邮件附件发送?

转载 作者:太空宇宙 更新时间:2023-11-03 11:32:05 24 4
gpt4 key购买 nike

在弄清楚 PhpMailer 之后,我现在一直专注于如何将文件移出数据库并将其作为附件附加到电子邮件中。在 phpMailer 站点上声明附件必须具有 4 个细节才能附加,即: $mail->addAttachment($path, $name, $encoding, $type);我有其中的 3 个,但从我的数据库下载中知道我没有 $path。我想到了将我的文件从我的数据库移动到一个临时位置,然后作为附件上传的可能性,但是,我找不到任何东西。我有能力从数据库下载我的文件。我在下面包含了该代码。

这是我的 PHPMailer 文件中的代码:

m->isHTML(true);
//adding file to be attached
$m->addAttachment($path, $name, $encoding, $type);

$m->Subject = "Here is an Email";
$m->Body = "<p>This is the body of the email</p><br><strong>Test for
HTML formatting</strong><br>";
$m->AltBody = "This is the body of an email";
$m->send();
echo "message has been sent";

这是我的文件下载文件中的代码。

$filename = $rows['name'];
$filesize = $rows['filesize'];
$content = $rows['wholeMP3'];
$type = $rows['type'];

header("Content-length: $filesize");
header("Content-type: $type");
header("Content-Disposition: attachment; filename=$filename");
ob_clean();
flush();
echo $content;
$LastProduct->closeCursor();

最佳答案

你不需要保存到一个文件,你可以使用一个字符串:

AddStringAttachment($string,$filename,$encoding,$type)

https://github.com/PHPMailer/PHPMailer/wiki/Tutorial

关于php - 在 PHP 中,如何从 mysql 数据库中检索文件并作为电子邮件附件发送?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48969605/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com