【发布时间】:2011-04-30 16:25:59
【问题描述】:
我在 IIS6 上运行 PHP。我有一些 PHP 成功地将 1KB 图像作为电子邮件附件发送。然而,当我尝试附加一个 500KB 的 PDF(更改了 Content-Type)时,它挂起,几分钟后我收到“FastCGI 进程超出配置的请求超时”(错误号 258 (0x80070102))。
对于为什么附加 PDF 需要这么长时间有什么想法吗?解决方案不是增加超时限制,我不能让用户在文件发送时坐在那里超过 3 分钟。
我在下面包含了我的代码:
$headers = "From: ".$from."\r\n";
$headers .= "Reply-To: ".$from."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$headers .="This is a multipart message in MIME format. \r\n\r\n";
$headers .= "--".$uid."\r\n\r\n";
$headers .= "Content-Type: text/plain; charset-iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n";
$headers .= $text . "\r\n\r\n";
$headers .= "--".$uid."\r\n\r\n";
$headers .= "Content-Type: text/html; charset-iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$headers .= $html . "\r\n\r\n";
$headers .= "--".$uid."\r\n\r\n";
$headers .= "Content-Type: image/png; name=\"".$filename."\"\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$attachment = chunk_split(base64_encode(file_get_contents($path.$filename)));
$headers .= $attachment . "\r\n\r\n";
$headers .= "--".$uid."\r\n\r\n";
//send the email
$mail_sent = @mail( $to, $subject, $text, $headers );
提前感谢您的任何建议。
【问题讨论】:
-
您确定不是 PDF 的实际生成导致脚本超时?
-
这听起来与附件文件大小无关。附件大小取决于邮件服务器设置,通常至少为 2mb
-
嗨,我不是在生成 PDF,而是从文件系统附加 PDF。我试过附加一个 60KB PDF 和 1KB PNG,花了 24 秒。如果我添加 570KB PDF,它会超时。
-
这是花费时间的编码 - 如果我删除 base64_encode 调用,电子邮件会立即发送,但附件当然已损坏。
标签: php email iis-6 mime attachment