首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将PDF附加到电子邮件后显示不正确

将PDF附加到电子邮件后显示不正确
EN

Stack Overflow用户
提问于 2014-03-18 20:41:38
回答 1查看 95关注 0票数 0

我们有一个在线测试,一旦完成,我们可以电子邮件给用户。然而,这些数据并不是以PDF格式附加的,而是以随机字母/数字的形式出现在电子邮件中。

对是什么原因有什么建议吗?一直持续到几个月前。

下面是代码:

代码语言:javascript
复制
<?php

$i_get_sid = isset($_GET["sid"]) ? (int)$_GET["sid"] : $i_sid;
$i_get_pass = isset($_GET["a"]) ? $_GET["a"] : $_SESSION['r_pass'];
$i_get_pass = addslashes($i_get_pass);

$i_qry1 = db_qry("SELECT * FROM reports WHERE sid={$i_get_sid} AND ispurchased=1 AND isenabled=1 AND passhash='$i_get_pass'")
 or die("Error: report-4, SQL request error #1 ".mysql_error());
if($i_qry1) {
    if($i_rec1=mysql_fetch_array($i_qry1)) {
        $i_fname = $i_rec1["fname"];
        $i_lname = $i_rec1["lname"];
        $i_email = $i_rec1["email"];
    }
    db_free_result($i_qry1);
}

if(!empty($i_email)) {
    ob_start();
    include('inc/pages/report-3.inc.php');
    $data = ob_get_contents();
    ob_end_clean();
    $data = wordwrap(base64_encode($data), 72, "\n", true);
    $i_boundary = '----------'.bin2hex(mhash(MHASH_MD5, time()));
    $i_headers = "From: oursite.com <info@oursite.com>
X-Mailer: oursite.com PHP Mail (v1.0)
Reply-To: oursite.com <info@oursite.com>
X-Priority: 3 (Normal)
MIME-Version: 1.0
Content-Type: multipart/mixed;
 boundary=\"$i_boundary\"";
    $i_message = "--$i_boundary
Content-Type: text/plain;
    charset=\"iso-8859-1\"
Content-Transfer-Encoding: 7bit

Dear ".$i_fname." ".$i_lname.",

Here is the report you asked for, attached as an Adobe Acrobat document.

If you do not already have one, an Adobe Acrobat reader can be downloaded
for free at http://www.adobe.com/.

----
Best regards,
OurSite Team
mailto:info@oursite.com

--$i_boundary
Content-Type: APPLICATION/PDF; name=\"report.pdf\"
Content-transfer-encoding: base64
Content-Disposition: attachment; filename=\"report.pdf\"

$data

{$i_boundary}--
";

    @mail($i_email, 'Our Site - Your Report', $i_message, $i_headers);
    @mail('null@sight2k.com', 'Our Site - Your Report', "ID - $i_get_sid", $i_headers);
}

header('Content-type: text/html');
$m_header = '<link href="shared/report.css" rel=stylesheet type="text/css">';
require_once($DOCUMENT_ROOT."inc/top-2.inc.php");
$i_get_sid = isset($_GET["sid"]) ? (int)$_GET["sid"] : $i_sid;

$i_get_pass = isset($_GET["a"]) ? $_GET["a"] : $_SESSION['r_pass'];
$i_get_pass = addslashes($i_get_pass);

echo '<table cellpadding=0 cellspacing=0 border=0 width="100%">';
echo '<tr vAlign=top><td height=7><img src="images/1x1.gif" width=1 height=7></td></tr>';
echo '<tr height=28 style="background: url(images/bookm-bg.gif) repeat-x"><td width="100%"><nobr>';
echo '<img src="images/1x1.gif" width=5 height=1><a href="report.php?sid='.$i_get_sid.'&a='.urlencode($i_get_pass).'"><img src="images/bookm-42.gif" width=67 height=28 border=0></a><a href="report.php?sid='.$i_get_sid.'&a='.urlencode($i_get_pass).'&b=pdf"><img src="images/bookm-s3.gif" width=10 height=28 border=0><img src="images/bookm-52.gif" width=65 height=28 border=0></a>&nbsp;<a href="report.php?sid='.$i_get_sid.'&a='.urlencode($i_get_pass).'&b=/report.pdf"><img src="images/button-downloadpdf.gif" width=80 height=28 border=0></a>&nbsp;&nbsp;<a href="report.php?sid='.$i_get_sid.'&a='.urlencode($i_get_pass).'&b=email"><img src="images/button-emailpdf.gif" width=80 height=28 border=0></a>';
echo '</nobr></td><td><nobr><font style="font-size: 10px;"><a href="javascript:window.close();">Close Window</a>&nbsp;</font></nobr></td></tr></table>';
echo "<p>&nbsp;Thank you.";
echo "<p>&nbsp;Your report has been successfully sent.";
require_once($DOCUMENT_ROOT."inc/btm-2.inc.php");

// header("location: report.php?sid=$i_get_sid&a=".urlencode($i_get_pass));

?>

下面是用户电子邮件中到达的一个例子(随机文本会持续很长时间,所以我只粘贴了几行):

代码语言:javascript
复制
Dear "user",

Here is the report you asked for, attached as an Adobe Acrobat document.

If you do not already have one, an Adobe Acrobat reader can be downloaded
for free at http://www.adobe.com/.

----
Best regards,
Our Site
mailto:info@oursite.com

------------2040d59fa64b69be819a8c22f7d6c114
Content-Type: APPLICATION/PDF; name="report.pdf"
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="report.pdf"

JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNl
cyAyIDAgUgovQ29udGVudHMgNCAwIFI+PgplbmRvYmoKNCAwIG9iago8PC9GaWx0ZXIgL0Zs
YXRlRGVjb2RlIC9MZW5ndGggMzE1Pj4Kc3RyZWFtCnicdVLLTsMwELznK+YIUnHtXTuxb0BL
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-03-18 20:44:28

这部分是错误的:

代码语言:javascript
复制
boundary=\"$i_boundary\"";

从代码的外观来看,这应该是:

代码语言:javascript
复制
boundary=\"--$i_boundary\"";

其次,我建议PHPMailer -它是如此容易得多!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/22490570

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档