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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T18:31:34+00:00 2026-06-17T18:31:34+00:00

To make life difficult, the client I’m working for is using a really large

  • 0

To make life difficult, the client I’m working for is using a really large yet old system which runs on PHP4.0 and they’re not wanting any additional libraries added.

I’m trying to send out an email through PHP with both an attachment and accompanying text/html content but I’m unable to send both in one email.

This sends the attachment:

$headers = "Content-Type: text/csv;\r\n name=\"result.csv\"\r\n Content-Transfer-Encoding: base64\r\n Content-Disposition: attachment\r\n boundary=\"PHP-mixed-".$random_hash."\"";
$output = $attachment;

mail($emailTo, $emailSubject, $output, $headers);

This sends text/html:

$headers = "Content-Type: text/html; charset='iso-8859-1'\r\n";
$output = $emailBody; // $emailBody contains the HTML code.

This sends an attachment containing the text/html along with the attachment contents:

$headers = "Content-Type: text/html; charset='iso-8859-1'\r\n".$emailBody."\r\n";
$headers = "Content-Type: text/csv;\r\n name=\"result.csv\"\r\n Content-Transfer-Encoding: base64\r\n Content-Disposition: attachment\r\n boundary=\"PHP-mixed-".$random_hash."\"";
$output = $attachment;

What I need to know is how can I send an email with text/html in the email body and also add an attachment to it. I’m sure I’m missing something really simple here!

Thanks in advance.

  • 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-17T18:31:35+00:00Added an answer on June 17, 2026 at 6:31 pm

    Okay, I’ve finally cracked it! For reference:

    $emailBody .= "<html><body>Blah</body></html>";
    $emailSubject = "Subject";
    $emailCSV = "\"Col1\", \"Col2\"\r\n"; // etc.
    $attachment = $emailCSV;
    
    $boundary = md5(time());
    
    $header = "From: Name <address@address.com>\r\n";
    $header .= "MIME-Version: 1.0\r\n";
    $header .= "Content-Type: multipart/mixed;boundary=\"" . $boundary . "\"\r\n";
    
    $output = "--".$boundary."\r\n";
    $output .= "Content-Type: text/csv; name=\"result.csv\";\r\n";
    $output .= "Content-Disposition: attachment;\r\n\r\n";
    $output .= $attachment."\r\n\r\n";
    $output .= "--".$boundary."\r\n";
    $output .= "Content-type: text/html; charset=\"utf-8\"\r\n";
    $output .= "Content-Transfer-Encoding: 8bit\r\n\r\n";
    $output .= $emailBody."\r\n\r\n";
    $output .= "--".$boundary."--\r\n\r\n";
    
    mail($emailTo, $emailSubject, $output, $header);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a little program to make my life easier when using Microsoft
What are your favorite Git configuration settings which make your life easy while working
I know enough about cryptology to make life difficult for a novice programmer and
Autocomplete inputs make life easier. However, I am working on a project where the
I am working on a game with some friends, and to make life easier
This may be a really long stretch but would make life a fair bit
It would make life so much easier!
I'm thinking about frameworks. I know they make life a lot easier, but as
I have a small RIA that I built as a learning/make-my-life-easier project that uses
I have to make a mobile app that calculates the real life size of

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.