# \[php\] email attachment

**URL:** <https://forum.kirupa.com/t/php-email-attachment/213324>\
**Category:** programming\
**Created:** [January 18, 2007, 6:21pm UTC](https://forum.kirupa.com/t/php-email-attachment/213324 "2007-01-18T18:21:00Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![NeoDreamer](https://avatars.discourse-cdn.com/v4/letter/n/ccd318/32.png) [@NeoDreamer](https://forum.kirupa.com/u/NeoDreamer)\
**Post date:** [January 18, 2007, 6:21pm UTC](https://forum.kirupa.com/t/php-email-attachment/213324/1 "2007-01-18T18:21:00Z")

</div>

I have a form that can send an email attachment. Everything is working (subject , attachment, etc…) except that the main message is empty. What did I do wrong?

```php

// send the message
$att = $_FILES['design'];
$att_path = $_FILES['design']['tmp_name'];
$att_name = $_FILES['design']['name'];
$att_size = $_FILES['design']['size'];
$att_type	= $_FILES['design']['type'];

$fp	= fopen($att_path, "rb");
$file = fread($fp, $att_size);
fclose($fp);

$num = md5(time());
$str = "==Multipart_Boundary_x{$num}x";

$file = chunk_split(base64_encode($file));

$hdr = "MIME-Version: 1.0
";
$hdr .= "Content-Type: multipart/mixed; ";
$hdr .= "boundary=\"{$str}\"
";
$hdr .= "From: $from 
";

$msg = "This is a multi-part message in MIME format

";
$msg .= "--{$str}
";
$msg .= "Content-Type: text/plain; charset=\"iso-8859-1\"
";
$msg .= "Content-Transfer-Encoding: 8bit
";
$msg .= "Name: $name
";
$msg .= "E-mail: $email
";
$msg .= "Title: $title
";
$msg .= "Comment: $comment
";
$msg .= "Agree: $agree

";
$msg .= "--{$str}
";

$msg .= "Content-Type: {$att_type}; ";
$msg .= "name=\"{$att_name}\"
";
$msg .= "Content-Disposition: attachment; ";
$msg .= "filename=\"{$att_name}\"
";
$msg .= "Content-Transfer-Encoding: base64
";
$msg .= "$file

";
$msg .= "--{$str}";

mail($to, "Submission", $msg, $hdr);
echo("<center><p>Submission Sent.</p></center>");

```
