简体   繁体   English

如何使用php邮件发送大型附件

[英]How to send large attachment using php mail

I'm new using php mail and I was trying to send an attachment with at least 1.5 Mb but it doesn't work, but for small size images it works. 我是使用php邮件的新手,我试图发送至少1.5 Mb的附件,但是它不起作用,但是对于小尺寸图像,它可以工作。 I've already configure my php.ini to higher values like upload_max_filesize, post_max_size, max_execution_time and max_input time. 我已经将php.ini配置为更高的值,例如upload_max_filesize,post_max_size,max_execution_time和max_input time。 but still nothing works. 但仍然没有任何效果。 I've been searching the net for some answers but still no possible solution. 我一直在网上寻找一些答案,但仍然没有可能的解决方案。 Can Anyone help me? 谁能帮我? thank you in advance 先感谢您

<?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();







?>

to set the value of upload_max_filesize and post_max_size in your php.ini : 在您的php.ini中设置upload_max_filesize和post_max_size的值:

Maximum allowed size for uploaded files. 上载文件的最大允许大小。

upload_max_filesize = 40M

; ; Must be greater than or equal to upload_max_filesize 必须大于或等于upload_max_filesize

post_max_size = 40M

check this question PHP change the maximum upload file size 检查此问题PHP更改最大上传文件大小

Have you checked the recipient's mail box size limit, attachment limit to ensure the mail you are sending falls within the limit? 您是否检查了收件人的邮箱大小限制和附件限制,以确保要发送的邮件在限制之内?

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM