现在弄清楚了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/