【问题标题】:How to send large attachment using php mail如何使用 php 邮件发送大附件
【发布时间】:2014-02-04 06:17:27
【问题描述】:

我是使用 php 邮件的新手,我试图发送至少 1.5 Mb 的附件,但它不起作用,但对于小尺寸图像它可以工作。我已经将我的 php.ini 配置为更高的值,例如 upload_max_filesize、post_max_size、max_execution_time 和 max_input time。但仍然没有任何效果。我一直在网上寻找一些答案,但仍然没有可能的解决方案。谁能帮我?提前谢谢你

<?php

    /* Set e-mail recipient */
    $myemail = "test@yahoo.com";



    //*** Get values form fields ***//
    $contact = $_POST['contact'];
    $strtitle = $_POST["txtSubject"];
    $type = $_POST['type'];
    $message = $_POST['txtDescription'];
    $message = wordwrap($message, 70);

    $message = "

                    <b> Contact No:</b>  $contact <br><br>


                        <b>Description:</b><br>
                        $message <br>

                        <b>Type</b> : $type


                ";

    //*** Uniqid Session ***//
    $strSid = md5(uniqid(time()));

    $strHeader = "";

    $strHeader .= "MIME-Version: 1.0\n";
    $strHeader .= "Content-Type: multipart/mixed; boundary=\"".$strSid."\"\n\n";
    $strHeader .= "This is a multi-part message in MIME format.\n";

    $strHeader .= "--".$strSid."\n";
    $strHeader .= "Content-type: text/html; charset=utf-8\n";
    $strHeader .= "Content-Transfer-Encoding: 7bit\n\n";
    $strHeader .= $message."\n\n";





    // *** Attachment ***//

    if($_FILES["fileAttach"]["name"] != "")
    {
        $strFilesName = $_FILES["fileAttach"]["name"];
        $strFileName = ($_FILES["fileAttach"]["size"]  < 1000000);
        $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"]))); 
        $strHeader .= "--".$strSid."\n";
        $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n"; 
        $strHeader .= "Content-Transfer-Encoding: base64\n";
        $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";

         $strHeader .= $strContent."\n\n";
    }


    $flgSend = @mail($myemail,$strtitle,null,$strHeader);  // @ = No Show Error //

    if($flgSend)
    {
        echo "<script type='text/javascript'>
                                    alert('Report Successfully Sent');window.location.href='Bug.php';
                                </script>"; 

        // echo "Size: " . ($_FILES["fileAttach"]["size"]);

    }
    else

    //Alert when Cannot connect to server
    {
        echo "<script type='text/javascript'>
                                    alert('Report Failed to Send : Server Connection Timed Out');window.location.href='Bug.php';
                                </script>";

        // echo "Size Failed: " . ($_FILES["fileAttach"]["size"]);

    }


exit();







?>

【问题讨论】:

  • 你能给我们看看代码吗,这样,也许我们可以帮助你?
  • 检查了错误日志,上面写着“连接正常关闭。”
  • 用我正在使用的 php 代码更新了我的帖子
  • 还检查了您的邮件服务器日志?安装了哪个操作系统?

标签: php file-upload


【解决方案1】:

在您的 php.ini 中设置 upload_max_filesize 和 post_max_size 的值:

上传文件的最大允许大小。

upload_max_filesize = 40M

;必须大于或等于upload_max_filesize

post_max_size = 40M

检查这个问题 PHP change the maximum upload file size

【讨论】:

  • 嗨 krish,我已经按照你说的设置了值,但仍然没有运气。我无法上传大文件的任何可能原因?
【解决方案2】:

您是否检查了收件人的邮箱大小限制、附件限制以确保您发送的邮件在限制范围内?

http://en.wikipedia.org/wiki/Comparison_of_webmail_providers

【讨论】:

    猜你喜欢
    • 2011-03-24
    • 1970-01-01
    • 1970-01-01
    • 2015-10-24
    • 2017-03-23
    • 1970-01-01
    • 2011-01-02
    • 2012-10-19
    相关资源
    最近更新 更多