PHP mail() email size limit

13,023

Solution 1

what I do with large attachments (for example pdf) is base encode the files myself:

$file = "/home/path/to/file.pdf";
$fp = @fopen($file, "rb");
$pdf_data = @fread($fp, filesize($file));
@fclose($fp);
$pdf_data = chunk_split(base64_encode($pdf_data));
$mail->AddStringAttachment($pdf_data, "filename.pdf", "base64", "application/pdf");

got no problems sending large files

Solution 2

I have read that on some email server there is a 7 MB limit, could this be limited by the hosting somehow?

Very likely this is your problem. PHPMailer uses the web server's sendmail function or whatever mail server is installed. Normally there is a (default) limit to the message size. For Postfix this would be:

message_size_limit (default: 10240000)
The maximal size in bytes of a message, including envelope information.
http://www.postfix.org/postconf.5.html

You will have to contact your hosting provider to change that.

Share:
13,023
TeeJay
Author by

TeeJay

I <3 Programming Laravel web applications in PHP Creating HTML5 websites and designing them in Photoshop Computers generally - building and overclocking them, high-performance PCs, eyefinity English! Playing the ukulele :) Driving my sports car Sports - volleyball, running, orienteering, MTB biking, snowboarding and skateboarding

Updated on July 01, 2022

Comments

  • TeeJay
    TeeJay almost 2 years

    I just wanna ask, when I'm using PHPMailer to send information from a form with many attachments, it's sending everything ok unless the files are more than 7 MB in total.

    Everyhing on the server is set up right as you can see:

    memory_limit = 40M
    post_max_size = 40M
    upload_max_filesize = 40M
    file_uploads = On
    

    I have read something about PHP mail server limits. I have set the PHPMailer to send messages using PHP mail() function.

    What else could there be needed to setup? Where can be the problem? The code itself is really without any limits, so it has to be somewhere else.

    When the mail isn't sent, PHP doesn't seem to report any errors, I just get the message from

    if(!$mail->Send()) { } else
    

    I have read that on some email server there is a 7 MB limit, could this be limited by the hosting somehow? Thank you for any help, I'm getting desperate.

    I also tried on our testing VPS server, it sends the mail everytime and when the files are bigger than 7 MB in total, it sends only some of the files with size < 7 MB.