【问题标题】:Is there a maximum reasonable file size to attach to a MIME email with PHP?使用 PHP 附加到 MIME 电子邮件是否有最大合理的文件大小?
【发布时间】: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


【解决方案1】:

将附件放在mail()函数的message参数中,而不是附加的headers参数中。

我今天遇到了同样的问题,发现我无法将大文件作为mail()函数中headers参数的一部分提交。

例如

$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"; 
$body .="This is a multipart message in MIME format. \r\n\r\n";

$body .= "--".$uid."\r\n\r\n";
$body .= "Content-Type: text/plain; charset-iso-8859-1\r\n";
$body .= "Content-Transfer-Encoding: quoted-printable\r\n\r\n";
$body .= $text . "\r\n\r\n";

$body .= "--".$uid."\r\n\r\n";
$body .= "Content-Type: text/html; charset-iso-8859-1\r\n";
$body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$body .= $html  . "\r\n\r\n";

$body .= "--".$uid."\r\n\r\n";
$body .= "Content-Type: image/png; name=\"".$filename."\"\r\n";
$body .= "Content-Transfer-Encoding: base64\r\n";
$body .= "Content-Disposition: attachment; filename=\"".$filename."\"\r\n\r\n";
$attachment = chunk_split(base64_encode(file_get_contents($path.$filename))); 
$body .= $attachment . "\r\n\r\n";

$body .= "--".$uid."\r\n\r\n";

//send the email 
$mail_sent = @mail( $to, $subject, $body, $headers );

【讨论】:

    猜你喜欢
    • 2012-06-29
    • 1970-01-01
    • 2011-11-22
    • 1970-01-01
    • 2013-07-22
    • 1970-01-01
    • 2014-08-21
    • 2019-07-01
    • 2010-12-07
    相关资源
    最近更新 更多