使用 PHP 附加到 MIME 电子邮件是否有最大合理文件大小?

发布于 2024-09-28 22:23:14 字数 1468 浏览 5 评论 0原文

我在 IIS6 上运行 PHP。我有一些 PHP 可以成功将 1KB 图像作为电子邮件附件发送。然而,当我尝试附加 500KB PDF(已更改内容类型)时,它会挂起,几分钟后我收到“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 );

提前感谢您的任何建议。

I run PHP on IIS6. I have some PHP that successfully sends a 1KB image as an attachment on an email. When I try and attach a 500KB PDF however (having changed the Content-Type), it hangs and after a few minutes I get "FastCGI process exceeded configured request timeout" (Error Number 258 (0x80070102)).

Any thoughts on why it's taking so long to attach the PDF? The solution is not to increase the timeout limit, I can't have users sitting there for 3+ minutes while the file gets sent.

I've included my code below:

    $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 );

Thanks in advance for any advice.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

余罪 2024-10-05 22:23:14

将附件放在 mail() 函数的消息参数中,而不是附加标头参数中。

我今天遇到了同样的问题,发现我无法将大文件作为 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 );

Put the attachment in the message parameter of the mail() function instead of the additional headers parameter.

I ran into the same problem today and found that I couldn't submit large files as part of the headers parameter in the mail() function.

e.g.

$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 );
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文