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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:03:50+00:00 2026-05-25T13:03:50+00:00

=======UPDATE======== The problem ended up being that I was using the header ContentType when

  • 0

=======UPDATE========

The problem ended up being that I was using the header ContentType when I should have been using Content-Type.

Thanks for your help guys.

Derp derp derp.

=======/UPDATE=======

I apologize in advance for the obnoxiously long question.

I’m attempting to send emails with attachments through PHP. I’ve done this successfully before with a single attachment. But I can’t get it to work with multiple attachments, or for that matter now with a single attachment using this method. So, what am I doing wrong?

I understand that there are other libraries for these functions available. But I want to know WHY this one is not working.

Here is the method that generates the actual email:

function gen_mail ()
{
    $files = $this->files();
    $has_attachments = (bool) $files;

    $EOL = "\r\n"; // tried \n, PHP_EOL
    $message = $this->message;

    $headers = $this->gen_headers();
    $headers .= "MIME-Version: 1.0$EOL";

    if ($has_attachments) {
        $hash = md5(time());
        $sep = "=={$hash}==";
        $headers .= "ContentType: multipart/mixed; boundary=\"$sep\"$EOL$EOL";
        $headers .= "This is a MIME-encoded message.$EOL$EOL";
        $headers .= "--$sep$EOL";
    }

    $headers .= "Content-Type: text/html; charset=\"iso-8859-1\"$EOL";
    $headers .= "Content-Disposition: inline$EOL";
    $headers .= "Content-Transfer-Encoding: 7bit$EOL$EOL";
    $headers .= "$message$EOL$EOL";

    if ($has_attachments) { // here go attachments
        foreach ($files as $key => $value) {
            $filename = is_numeric($key)? basename($value) : $key;
            $file = fopen($value, 'rb');
            $data = fread($file, filesize($value));
                            fclose($file);
            $content = chunk_split(base64_encode($data));
            $headers .= "--$sep$EOL";
            $headers .= "Content-Type: application/octet-stream; ";
            $headers .= "name=\"$filename\"$EOL";
            $headers .= "Content-Transfer-Encoding: base64$EOL";
            // tried Content-Disposition, attachment, and every combination
            $headers .= "Content-Description: inline; $EOL ";
            $headers .= "filename=\"$filename\"$EOL$EOL";
            $headers .= "$content$EOL$EOL";
        }
        $headers .= "--$sep--$EOL$EOL";
    }
    return $headers;
}

And this is what the headers returned by the above function look like:

From: test@urbido.es
MIME-Version: 1.0
ContentType: multipart/mixed; boundary="==cd42448edf10bca4640bc7d6365e1961=="

This is a MIME-encoded message.

--==cd42448edf10bca4640bc7d6365e1961==
Content-Type: text/html; charset="iso-8859-1"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit

Travis, you are so cool!!!1!

--==cd42448edf10bca4640bc7d6365e1961==
Content-Type: application/octet-stream; name="html.login.php"
Content-Transfer-Encoding: base64
Content-Description: inline; 
 filename="html.login.php"

PD9waHANCgkNCiRoZWFkZXJfY29uZmlnID0gYXJyYXkoKTsNCiRtc2cgPSAnUmVnaXN0ZXJlZCBP
cGVyYXRvcnMsIGVudGVyIHlvdXIgT3BlcmF0b3IgSUQgYW5kIHBhc3N3b3JkIHRvIGxvZ2luJzsN
CiRtc2dfY2xhc3MgPSAnbm9ybWFsJzsNCmlmICgkbG9nZ2VkX2luKSB7DQoJJGhlYWRlcl9jb25m
aWdbJ2NvbnRyb2xzJ10gPSBhcnJheSAoDQoJCWFycmF5ICgndGV4dCcgPT4gJ1N1Ym1pdCBFbnRy
aWVzJywgJ2hyZWYnID0+ICdlbnRyeScpLA0KCSk7DQoJJG1zZyA9ICdZb3UgYXJlIGxvZ2dlZCBp
bi4gVXNlIHRoZSBhYm92ZSBsaW5rcywgb3IgDQoJCWNsaWNrIDxhIGhyZWY9ImVudHJ5Ij5oZXJl
PC9hPiB0byBiZWdpbiBvciByZXN1bWUgYSBqb2InOw0KCSRtc2dfY2xhc3MgPSAnc3VjY2Vzcyc7
DQp9DQoNCj8+


--==cd42448edf10bca4640bc7d6365e1961==--

I’ve tried functions written by other people, and they produce seemingly identical output. But when I send those headers with
mail($address, $subject, ”, $headers)

I get this in my inbox:

This is a MIME-encoded message.

--==cd42448edf10bca4640bc7d6365e1961==
Content-Type: text/html; charset="iso-8859-1"
Content-Disposition: inline
Content-Transfer-Encoding: 7bit

Travis, you are so cool!!!1!

--==cd42448edf10bca4640bc7d6365e1961==
Content-Type: application/octet-stream; name="html.login.php"
Content-Transfer-Encoding: base64
Content-Description: inline;
 filename="html.login.php"

PD9waHANCgkNCiRoZWFkZXJfY29uZmlnID0gYXJyYXkoKTsNCiRtc2cgPSAnUmVnaXN0ZXJlZCBP
cGVyYXRvcnMsIGVudGVyIHlvdXIgT3BlcmF0b3IgSUQgYW5kIHBhc3N3b3JkIHRvIGxvZ2luJzsN
CiRtc2dfY2xhc3MgPSAnbm9ybWFsJzsNCmlmICgkbG9nZ2VkX2luKSB7DQoJJGhlYWRlcl9jb25m
aWdbJ2NvbnRyb2xzJ10gPSBhcnJheSAoDQoJCWFycmF5ICgndGV4dCcgPT4gJ1N1Ym1pdCBFbnRy
aWVzJywgJ2hyZWYnID0+ICdlbnRyeScpLA0KCSk7DQoJJG1zZyA9ICdZb3UgYXJlIGxvZ2dlZCBp
bi4gVXNlIHRoZSBhYm92ZSBsaW5rcywgb3IgDQoJCWNsaWNrIDxhIGhyZWY9ImVudHJ5Ij5oZXJl
PC9hPiB0byBiZWdpbiBvciByZXN1bWUgYSBqb2InOw0KCSRtc2dfY2xhc3MgPSAnc3VjY2Vzcyc7
DQp9DQoNCj8+


--==cd42448edf10bca4640bc7d6365e1961==--
  • 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-05-25T13:03:51+00:00Added an answer on May 25, 2026 at 1:03 pm

    You’ve got the wrong header. It’s “Content-Disposition”, not “Content-Description”. Try:

    Content-Disposition: attachment; filename="html.login.php"
    

    instead. Content-Description is to add a short DESCRIPTION of what the attachment is, e.g. “This is my resume” and has nothing to do at all with telling the mail client how to deal with the attachment.

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

Sidebar

Related Questions

Update : The problem appears to have been corrupt DLLs somewhere in my PHP
Update: The problem ended up being the Flash component itself. It wasn't properly compiling
Update II Problem Solved but Why? This has been the biggest headache ever. My
UPDATE It looks like this problem has been quietly fixed in iOS 4.3. Up
The problem: I often have to update two or more repositories: One for the
Update: After some more reading I see that this problem is totally general, you
A problem I recently ran into was that when trying to update a field
I currently have a problem attepting to update a record within my database. I
Figure there is a simple solution to this problem but I have been unable
Update (21st Sept 2016) - Thanks to Digbyswift for commenting that this solution still

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.