0
我們有一個在線測試,一旦完成,我們可以通過電子郵件發送給用戶。但是,數據並未作爲PDF附加,它在電子郵件中顯示爲一堆隨機字母/數字。將PDF附加到電子郵件無法正確顯示
有什麼建議是造成這種情況的原因?它直到幾個月前纔開始工作。
下面的代碼:
<?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 <[email protected]>
X-Mailer: oursite.com PHP Mail (v1.0)
Reply-To: oursite.com <[email protected]>
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:[email protected]
--$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('[email protected]', '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> <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> <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> </font></nobr></td></tr></table>';
echo "<p> Thank you.";
echo "<p> 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));
?>
下面是用戶的電子郵件什麼到達一個例子(隨機文本那張很長一段時間,所以我剛剛粘貼幾行):
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:[email protected]
------------2040d59fa64b69be819a8c22f7d6c114
Content-Type: APPLICATION/PDF; name="report.pdf"
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="report.pdf"
JVBERi0xLjMKMyAwIG9iago8PC9UeXBlIC9QYWdlCi9QYXJlbnQgMSAwIFIKL1Jlc291cmNl
cyAyIDAgUgovQ29udGVudHMgNCAwIFI+PgplbmRvYmoKNCAwIG9iago8PC9GaWx0ZXIgL0Zs
YXRlRGVjb2RlIC9MZW5ndGggMzE1Pj4Kc3RyZWFtCnicdVLLTsMwELznK+YIUnHtXTuxb0BL
呵呵......我可以建議PHPMailer嗎? https://github.com/PHPMailer/PHPMailer –