php_nub_qq Posted May 21, 2013 Share Posted May 21, 2013 (edited) Hi, I recently made a function to my website where users can download a full chat history with a certain friend of theirs instead of just showing the whole history in the browser and most probably crashing it ( if they've chatted for quite some time ). So everything works well except the fact that I can't send large files. I suppose the largest I could send was 10mb or something like that ( could be lying ). Anyway that's way less than I need so it doesn't really matter. What I need is to be able to send around 50mb of data and I believe the changes that need to be done are a matter of the mailing server. Unfortunately I'm using a hosting service and I have limited access to those things. Can anyone help me out? EDIT: I just saw that the allowed size is in the error: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 76903277 bytes) EDIT 2: Actually the allowed is larger than the filesize, now I'm confused Edited May 21, 2013 by php_nub_qq Quote Link to comment https://forums.phpfreaks.com/topic/278251-php-mail-attachment-max-size/ Share on other sites More sharing options...
jazzman1 Posted May 21, 2013 Share Posted May 21, 2013 Chunk the data to 1MB and start the php mail function to send 1 MB in every 1 min with sleep ( int $seconds ). Also, you need to know what is the value of max execution time provided by your hosting provider in the php.ini file. Quote Link to comment https://forums.phpfreaks.com/topic/278251-php-mail-attachment-max-size/#findComment-1431463 Share on other sites More sharing options...
php_nub_qq Posted May 22, 2013 Author Share Posted May 22, 2013 Chunk the data to 1MB and start the php mail function to send 1 MB in every 1 min with sleep ( int $seconds ). Also, you need to know what is the value of max execution time provided by your hosting provider in the php.ini file. How do I chunk it to 1MB and wouldn't that send 50 emails ( for 50 mb file ) ? Here's the code as well: $file = 'ads2.zip'; // 60mb file for testing purposes $file_name = $file; // file name and file path match $to = 'myemail@asd.com'; $subject = 'the subject'; $from = 'dgd@dgd.dgd'; $message = "<h1>some HTML</h1>"; $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/html; charset=\"utf-8\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; $message .= "--{$mime_boundary}\n"; // preparing attachments $content = chunk_split(base64_encode(file_get_contents($file))); $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$file_name\"\n" . "Content-Disposition: attachment;\n" . " filename=\"$file_name\"\n" . "Content-Transfer-Encoding: base64\n\n" . $content . "\n\n"; // 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>"; } the code is gotten from here https://gist.github.com/optikalefx/5149537 and was modified a little Quote Link to comment https://forums.phpfreaks.com/topic/278251-php-mail-attachment-max-size/#findComment-1431491 Share on other sites More sharing options...
jazzman1 Posted May 22, 2013 Share Posted May 22, 2013 .....and wouldn't that send 50 emails ( for 50 mb file ) I know that's not very practical, but you need to be aware about few things. Most of the share hosting providers limits their outcoming mail size to 25 - 30 MB, on the other hand there is also a limit per email message you receive (incoming mail size) Many mail providers and ISPs will reject mail larger than 5-10 MB. Quote Link to comment https://forums.phpfreaks.com/topic/278251-php-mail-attachment-max-size/#findComment-1431536 Share on other sites More sharing options...
php_nub_qq Posted May 22, 2013 Author Share Posted May 22, 2013 Well is there any way I can verify the given maximum size of the outgoing emails? I also believe that the error I'm getting isn't related to this limit, and I'd really need help with that too. Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/278251-php-mail-attachment-max-size/#findComment-1431547 Share on other sites More sharing options...
jazzman1 Posted May 22, 2013 Share Posted May 22, 2013 Well, don't use the mail function then, just provide them a link to download their chat history from the server. Quote Link to comment https://forums.phpfreaks.com/topic/278251-php-mail-attachment-max-size/#findComment-1431551 Share on other sites More sharing options...
php_nub_qq Posted May 22, 2013 Author Share Posted May 22, 2013 (edited) That's not an option because the conversation is in the database and if I were to create a file on demand I would not be able to detect when it's download has been finished thus I cannot delete it, and even if I could if the user for some reason loses the file he has to generate a new one and that's just wasting resources and bandwidth, which is limited in my case. I just need to figure what's causing this error and how to prevent it and I'll manage from then on. REMINDER: Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 76903277 bytes) Edited May 22, 2013 by php_nub_qq Quote Link to comment https://forums.phpfreaks.com/topic/278251-php-mail-attachment-max-size/#findComment-1431554 Share on other sites More sharing options...
mac_gyver Posted May 22, 2013 Share Posted May 22, 2013 the error mentions an amount of memory larger than the file because the output from base64_encode is about 2/3 larger than the original. Quote Link to comment https://forums.phpfreaks.com/topic/278251-php-mail-attachment-max-size/#findComment-1431560 Share on other sites More sharing options...
php_nub_qq Posted May 22, 2013 Author Share Posted May 22, 2013 What can I do about this :? Quote Link to comment https://forums.phpfreaks.com/topic/278251-php-mail-attachment-max-size/#findComment-1431563 Share on other sites More sharing options...
mac_gyver Posted May 22, 2013 Share Posted May 22, 2013 break the file up into smaller pieces and send one at a time or don't try to send it as an email attachment. Quote Link to comment https://forums.phpfreaks.com/topic/278251-php-mail-attachment-max-size/#findComment-1431572 Share on other sites More sharing options...
Eiseth Posted May 22, 2013 Share Posted May 22, 2013 Because your script is taking too long to process due to larger files http://www.php.net/manual/en/ini.core.php#ini.memory-limit Either adding this at the top of your page ini_set('memory_limit', '-1'); or refactor your code Quote Link to comment https://forums.phpfreaks.com/topic/278251-php-mail-attachment-max-size/#findComment-1431577 Share on other sites More sharing options...
php_nub_qq Posted May 22, 2013 Author Share Posted May 22, 2013 Because your script is taking too long to process due to larger files http://www.php.net/manual/en/ini.core.php#ini.memory-limit Either adding this at the top of your page ini_set('memory_limit', '-1'); or refactor your code when I do ini_set('memory_limit', '-1'); there is no error but the mail doesn't get sent, which I suppose is due to the mail size limit. I will contact my hosting provider to see if I can negotiate something. Thank you guys for all the help! Quote Link to comment https://forums.phpfreaks.com/topic/278251-php-mail-attachment-max-size/#findComment-1431615 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.