【问题标题】:In PHP how can I retrieve file from mysql database and send as attachment in email?在 PHP 中,如何从 mysql 数据库中检索文件并作为电子邮件附件发送?
【发布时间】:2018-02-25 02:14:16
【问题描述】:

在弄清楚 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();

【问题讨论】:

    标签: php mysql phpmailer


    【解决方案1】:

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

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

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

    【讨论】:

    猜你喜欢
    • 2016-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-04-12
    • 2010-12-02
    • 2011-11-02
    • 1970-01-01
    相关资源
    最近更新 更多