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

  • SEARCH
  • Home
  • 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 8058963
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T09:30:55+00:00 2026-06-05T09:30:55+00:00

Hi i have code that sends email with multiple attachments, but i have problems

  • 0

Hi i have code that sends email with multiple attachments, but i have problems with one piece of that code below.

Whenever i submit image, i get “Unsuported file format!”. If i delete that part of code, it works great, but then user can send every type of file (that is dangerous, i know). Filesize check works great. What is wrong? :S

//*** Attachment ***//  
for($i=0;$i<count($_FILES["fileAttach"]["name"]);$i++)  
{
    $filesize = $_FILES["fileAttach"]["size"][$i]/1024;

    if($_FILES["fileAttach"]["name"][$i] != "" && $filesize < 50 && preg_match("image/", $_FILES["fileAttach"]["type"][$i]))  
    {  
    $strFilesName = $_FILES["fileAttach"]["name"][$i];  
    $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"][$i])));  
    $strHeader .= "--".$strSid."\n";  
    $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";  
    $strHeader .= "Content-Transfer-Encoding: base64\n";  
    $strHeader .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";  
    $strHeader .= $strContent."\n\n";  
    }
    elseif(!preg_match("image/", $_FILES["fileAttach"]["type"][$i])){
        die('<div id="warning">Unsuported file format!</div>');
    }
    elseif($filesize > 50){
        die('<div id="warning">Filesize must be less than 2 Mb!!!</div>');
        }
}
  • 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-05T09:30:57+00:00Added an answer on June 5, 2026 at 9:30 am
    $strHeader .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n";  
    

    should just be

    $strHeader .= "Content-type: application/octet-stream\n";
    

    with no filename portion. That goes onto the content-disposition line.

    In the bigger picture view, don’t build your own mime emails. As you’re finding out, it’s painful and ugly. Use PHPMailer or Swiftmailer to do it for you – that whole attachment business can be reduced to a SINGLE function call with either library.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a piece of code that sends email.. heres the code This is
I have some code that sends an email with an attachment. I get the
Hey I have this code that sends an email with some data sent by
I have a section of code that sends email from SMTP server. The code
I have some code that I want to make public. The code sends email
I have written a code that sends out Email from Windows Service. Now when
I currently have existing code that automates and email and sends files. I now
I have code that sends emails to users from a signup webpage. Occasionally, users
I have code that I want to compile on all unix systems, but if
I have a rails code that sends emails. Following is in my controller: def

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.