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 8377535
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:41:45+00:00 2026-06-09T15:41:45+00:00

I use the following code to create and send the csv file to a

  • 0

I use the following code to create and send the csv file to a specific mail box in php. I can successfully receive the csv file, however, I do not understand why one more txt file called ATT00001.txt is attached also. Can anyone help me to take a look?

Here is the part of code for sending the mail:

// email fields: to, from, subject, and so on 
$to = "you@home.com"; 
$from = "me@home.com";  
$subject ="Test mail";  
$message = "please check the csv out!"; 
$headers = "From: $from"; 

$fileName = pathtocsv;

// boundary  
$semi_rand = md5(time());  
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";  

// headers for attachment  
$headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\"";  

// multipart boundary  
$message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n";  
$message .= "--{$mime_boundary}\n"; 

// preparing attachments 
$file = fopen($fileName,"rb"); 
$data = fread($file,filesize($fileName)); 
fclose($file); 
$data = chunk_split(base64_encode($data)); 
$message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"record.csv\"\n" .  
"Content-Disposition: attachment;\n" . " filename=\"test.csv\"\n" .  
"Content-Transfer-Encoding: base64\n\n" . $data . "\n\n"; 
$message .= "--{$mime_boundary}\n"; 

mail($to, $subject, $message, $headers);

One more text file is sent

And when I view it, it is just an empty txt file. I open the mail in Outlook.

  • 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-09T15:41:46+00:00Added an answer on June 9, 2026 at 3:41 pm

    Changing the last boundary line:

    $message .= "--{$mime_boundary}\n";
    

    to:

    $message .= "--{$mime_boundary}--\n";
    

    Note the extra -- at the end.

    RFC 2046 ( § 5.1.1 – Common Syntax [page 19]) states that:

    The boundary delimiter line following the last body part is a
    distinguished delimiter that indicates that no further body parts
    will follow. Such a delimiter line is identical to the previous
    delimiter lines, with the addition of two more hyphens after the
    boundary parameter value.

    –gc0pJq0M:08jU534c0p–

    Since the last boundary was missing, it seems to be the default behaviour that Outlook creates an attachment containing some extra data or an empty attachment.

    The second answer here by James-Luo may also be valid. He states that adding an attachment to a MIME message prior to the message body can result in similar outcome with the attachments.

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

Sidebar

Related Questions

I use the following code... $mail = new PHPMailer(); $mail->IsSMTP(); // send via SMTP
I use following code: Create a retry policy, when error, retry after 1 second,
I use the following code try to create an array of string vectors, I
If I use the following code to create a sender and receiver qsender =
I just use following code to add an image to my project, var paper
I use VS2010, C# to develop Silverlight 4 app, I use following code in
I have an array of objects, and i use following code to get in
I use the following code to crop an image according to a rectangular selection
I use the following code to copy a particular directory and its contents to
I use the following code to fill all empty keys in sub-arrays with ``

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.