我制作了一个简单的电子邮件注册系统,其中包含验证的md5哈希值。当遵循验证链接并且帐户变为“活动”时,我正在尝试向用户发送pdf。这有时是有效的,而不是其他的。我使用以下代码:
$subject = 'Your free PDF';
$random_hash = md5(date('r', time()));
$headers = "From: info@mysite.com\r\nReply-To: info@mysite.com";
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\"";
$attachment = chunk_split(base64_encode(file_get_contents('../../assets/Free PDF.pdf')));
ob_start(); //Turn on output buffering
?>
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>"
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hi,
Please find attached your free PDF.
~ The Team
--PHP-alt-<?php echo $random_hash; ?>
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
Hi,<br>
<br>
Please find attached your free <strong>PDF</strong>.
<br>
~ The Team
--PHP-alt-<?php echo $random_hash; ?>--
--PHP-mixed-<?php echo $random_hash; ?>
Content-Type: application/pdf; name="Free PDF.pdf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment
<?php echo $attachment; ?>
--PHP-mixed-<?php echo $random_hash; ?>--
<?php
//copy current buffer contents into $message variable and delete current output buffer
$message = ob_get_clean();
//send the email
$mail_sent = @mail( $email, $subject, $message, $headers );
如果它不能与电子邮件一起使用,它将无法使用该电子邮件地址。例如,有人使用网络邮件在yahoo.com地址收到了它。我在另一个上测试了相同的,它运行良好。它并不是垃圾邮件或任何东西,它转到电子邮件,然后下载的PDF无效,并且看起来大小不同。