-1

面临的问题:尝试使用 PHP 发送电子邮件,最多 20 MB 数据作为电子邮件附件,所有文件都是 .pdf 文件。我可以成功发送最多 5 MB 的电子邮件,但如果尝试发送超过 5 MB 的数据,我的收件箱中从未收到电子邮件,PHP 也没有显示错误。我在许多论坛上搜索过这个问题,并尝试了他们提供的所有解决方案。就像 php.ini 文件中的设置一样。

php.ini 设置:

memory_limit = 256M

max_execution_time = 60

max_file_uploads = 25

post_max_size = 25M

upload_max_filesize = 10M

我正在使用的代码:

        $to = $settings->factoring_email; 
        $from = ucfirst($settings->company_name)."<".$settings->company_billing_email.">";

        $subject = ucfirst($settings->company_name).' Invoice Manifest '.$post['inv_date'];
        $message = "Please see attached documents.";
        $headers = "From: $from";

        // boundary
        $semi_rand = md5(time());
        $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
        // headers for attachment
        $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";
        // multipart boundary
        $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";
        $message .= "--{$mime_boundary}\n";

        // preparing attachments
        $count = count($files);
        for($x=0;$x<$count;$x++){
            if(stristr($files[$x],'manifest')) {
                $path = BASE_PATH.DS.'docs'.DS.'tmp'.DS.$files[$x];
                $name = $files[$x];
            }
            else {
                $path = BASE_PATH.DS.'docs'.DS.'load_info'.DS.$files[$x].'.pdf';
                $name = $files[$x].'.pdf';
            }

            if(file_exists($path)) {
                $file = fopen($path,"rb");
                $data = fread($file,filesize($path));
                fclose($file);
                $data = chunk_split(base64_encode($data));
                $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$name\"\n" .
                "Content-Disposition: attachment;\n" . " filename=\"$name\"\n" .
                "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n";
                $message .= "--{$mime_boundary}\n";

                unset($file, $data);
            }
        }
        // send

        $ok = mail($to, $subject, $message, $headers);

        if ($ok) {
            echo "<p>mail sent to $to!</p>";
        } else {
            echo "<p>mail could not be sent!</p>";
        }
4

2 回答 2

2

如果您成功发送了较小的邮件,我敢打赌这更有可能是您的邮件服务配置的问题。您的邮件路线上的某个人不允许“大”邮件通过。检查您的回复地址,看看是否有任何退回。

于 2013-03-21T18:23:21.567 回答
0

您永远不会在收件箱中收到电子邮件,因为电子邮件永远不会在途中发送。电子邮件被该函数联系的 SMTP 服务器或该函数产生mail()的程序拒绝。mail()

这两种情况中的哪一种取决于您与邮件相关的 PHP 配置

于 2013-03-21T22:13:52.010 回答