Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mail() email size limit

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.

like image 867
TeeJay Avatar asked Jun 14 '13 07:06

TeeJay


2 Answers

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

like image 173
Bokw Avatar answered Jan 04 '23 08:01

Bokw


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.

like image 35
Simon Avatar answered Jan 04 '23 07:01

Simon