在php中生成附件并使用它发送电子邮件?

时间:2013-03-08 12:53:02

标签: php email

我正在使用liveoc创建一个pdf文件并提示用户下载。我没有将文件保存到服务器就成功了,这就是目标。

我想生成完全相同的pdf并将其作为附件发送。我怎么能这样做。

我不知道这是否重要,但我会在下面添加相关代码:

download.php //创建pdf文件并提示用户下载的文件 //发送标题

header('Content-disposition: attachment; filename=Simulação.pdf');
header('Content-type: application/pdf');

// download.php的输出结果

echo(base64_decode($data));

//尝试发送电子邮件 - anotherfile.php

//define the from \ reply to headers
$headers = "From: $email_from\r\nReply-To: $email";

//create a unique boundary string to delimit different parts of the email (plain text, html, file attachment)

$random_hash = md5(date('r', time()));
//add boundary string and mime type specification
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";

//read the atachment file contents into a string,
//encode it with MIME base64,
//create file
$attachment = chunk_split(base64_encode(   WHAT DO I PUT HERE                  ));

//define the body of the message.
$message = "--PHP-mixed-$random_hash\r\n"
."Content-Type: multipart/alternative; boundary=\"PHP-alt-$random_hash\"\r\n\r\n";
$message .= "--PHP-alt-$random_hash\r\n"
."Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"
."Content-Transfer-Encoding: 7bit\r\n\r\n";

0 个答案:

没有答案