PHP mail() email size limit

TeeJay picture TeeJay · Jun 14, 2013 · Viewed 11.2k times · Source

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.

Answer

Bokw picture Bokw · Jun 14, 2013

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