Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8074091
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T14:32:37+00:00 2026-06-05T14:32:37+00:00

i have one form and i am using PHPMailer to send data from that

  • 0

i have one form and i am using PHPMailer to send data from that form to my email. Users can send attachments as well, but i have one rpoblem: how to make PHPMailer to deny attachments larger than 2Mb and to allow only iamge attachments (no other types of documents)?

This is code i using for multiply email attachments with PHPMailer:

foreach(array_keys($_FILES['fileAttach']['name']) as $key) {

   $source = $_FILES['fileAttach']['tmp_name'][$key]; 
   $filename = $_FILES['fileAttach']['name'][$key]; 

   $mail->AddAttachment($source, $filename);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T14:32:39+00:00Added an answer on June 5, 2026 at 2:32 pm

    you can check the filesize using filesize() and the type using mime_content_type().

    the resulting code could look like:

    $maxsize = 2 * 1024 * 1024; // 2 MB
    $types = array('image/png', 'image/jpeg', 'image/gif'); // allowed mime-types
    
    if(filesize($filename) < $maxsize && in_array(mime_content_type($filename),$types)){
      $mail->AddAttachment($source, $filename);
    }
    

    EDIT: PHPMailer doesn’t have a built-in possibility for those chacks – as you can see from the source, it only checks if the file exists when adding an attachment:

    if ( !@is_file($path) ) {
      throw new phpmailerException($this->Lang('file_access') . $path, self::STOP_CONTINUE);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have one contact form, when user submit all value will send(email) to admin.But
Using web forms I know that you can only have one ASP.NET form on
I have a form that im trying to get emailed on submit using PHPmailer.
I am creating one form in html using table. Which have one Drop down
I am using Asp.net dropdownlist in one of my form ..I have two dropdown
My problem is this one, I am using Sharepoint 2010, I have a form
I have one form in a PHP (5.2.9-1) application that causes IIS (Microsoft-IIS/6.0) to
I need to make the program which have one form that contains PNG image
I have one windows form file that each time I open it in Visual
Well, I have one form, similar to dajax django forms example, all is working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.