PHP Email content arriving as attachment
<p>I have this piece of PHP code, although it works, but the problem is that the email message content is sent as an attachment along with the intended attachment which means that when the email arrives, the body is blank but there's two attachments. One is the intended attachment and the other is the email content that is supposed to be displayed in the the email. Is there something I'm doing wrong?</p>

<p>Here's the full source code:</p>

<pre><code>&lt;?php
require('fpdf/fpdf.php');
include('./config.php');

$pdf = new FPDF('P', 'pt', 'Letter');
$pdf-&gt;SetAutoPageBreak(true, $margin);

$pdf-&gt;AddPage();
$pdf-&gt;SetFont('arial','',12);

   if(isset($_POST['accept'])){
    $id = $_POST['id'];
    $to = 'me@somewhere.com';
    $subject = urldecode($_POST['subject']);
    $message = urldecode($_POST['message']);

    $data = '';

    $result = mysql_query("select * from applications where id = $id");
    $row = $data_array = mysql_fetch_assoc($result);

    $data .= "Name: " . $row['name'] . " \n\n";
    $data .= "Surname: " . $row['surname'] . "\n\n";    
    $data .= "Age: ". $row['age'] . "\n\n";
    $data .= "Dob: ". $row['dob'] . "\n\n"; 
    $data .= "Height: ". $row['height'] . "\n\n";
    $data .= "Add1 : ".$row['address1'] . "\n\n";   
    $data .= "Add2:  ".$row['address2'] . "\n\n";   
    $data .= "Add3: ".$row['address3'] . "\n\n";
    $data .= "Postcode: ".$row['postcode'] . "\n\n";            
    $data .= "Town:  ".$row['town'] . "\n\n";   
    $data .= "County: ". $row['county']. "\n\n";    
    $pdf-&gt;SetX(140);

    $pdf-&gt;Ln(2);

    $pdf-&gt;MultiCell(0, 15, $data);

    $from     = "me@mydomain.com"; 

    $separator = md5(time());

    $eol = PHP_EOL;

    // attachment name
    $filename = "form.pdf";

    // encode data (puts attachment in proper format)
    $pdfdoc = $pdf-&gt;Output("", "S");
    $attachment = chunk_split(base64_encode($pdfdoc));

    // main header
    $headers  = "From: ".$from.$eol;
    $headers .= "MIME-Version: 1.0".$eol; 
    $headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";

    $body = "--".$separator.$eol;
    $body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;

    // message
    $body .= "--".$separator.$eol;
    $body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
    $body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
    $body .= $message.$eol;

    // attachment
    $body .= "--".$separator.$eol;
    $body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol; 
    $body .= "Content-Transfer-Encoding: base64".$eol;
    $body .= "Content-Disposition: attachment".$eol.$eol;
    $body .= $attachment.$eol;
    $body .= "--".$separator."--";

    // send message
    if(mail($to, $subject, $body, $headers)){

                echo "&lt;b&gt;Email successfully sent&lt;/b&gt;";
        }
    else{
         echo "Your message could not be sent.";
      }
}

?&gt;
</code></pre>

<p>Any help will be highly appreciated.</p>
