# Solved: php mail function attachment file size



## andynic (May 25, 2007)

Hi,

Which PHP parameter limits the size of a file attachment to an email sent using the php mail function?

I see, for example, upload_max_filesize and post_max_size whose values can be determined with the ini_get function.

On my server, the former is set to 2M and the latter to 8M. It seems to be the latter that affects the mail function as far as file size of attachments is concerned, or at least fetching the file and its size from $_FILES.

1. Am I drawing the correct conclusion, that is, that I should block attempts to attach files larger tan ini_get('post_file_size')
or
2. Is there some interaction between these two parameters, i.e. upload_max_filesize and post_file_size?
and/or
3. Are there other parameters I need to consider to be sure that the user's email gets sent with success?

Thanks for your help.
Andynic


----------



## andynic (May 25, 2007)

Problem solved:
If you check the value of $_FILES['attachment']['error'] it will be 0 for a successful upload, 1 if fail.

From the PHP Manual:
"Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini."

More precisely:
If the attachment size exceeds the PHP init parameter upload_max_filesize, $_FILES['attachment']['error'] will be 1 and, while the email may get sent, the attachment will not be with it upon arrival.

If the attachment size exceeds the PHP init parameter post_max_size, the script may behave in unexpected ways because it will cause various super globals such as $_POST and $_FILES not to be set. From the PHP Manual: 'If the size of post data is greater than post_max_size, the $_POST and $_FILES superglobals are empty."
Andynic


----------

