Email with attachment making me NUTS!

I’ve never had to add an attachment to a PHP email before so I spent a few hours reading as many tutorials as I could and then plowed into it … only to beat me head on the desk for hours!

Here’s the code (sorry it’s a mess from all the hacking I’ve been doing)

$body_plain = strip_tags($in_body);

$body_plain .= "
\
\
You are receiving this email because you opted into the NextHunt.com mailing list. To remove your name from this list please go to the following URL: ";

$body_html .= $in_body;

$body_html .= "
		<p>You are receiving this email because you opted into the NextHunt.com mailing list. To remove your name from this list please <a href=''>click this link</a></p>";


$body_html .= "
	</body>
</html>\
";

    $hash = md5(date('r', time()));

    $head[] = "From: {removed}";
    $head[] = "Reply-To: {removed}";

	if (!$has_attachment)	{
	    $head[] = 'Content-Type: multipart/alternative; boundary="PHP-alt-' . $hash . '"';
		}
	else	{
		$head[] = 'Content-Type: multipart/mixed; boundary="PHP-alt-' . $hash . '"';
		}
    $head[] = 'MIME-Version: 1.0';

    $body = "
--PHP-alt-{$hash}
Content-Type: text/plain; charset=\\"iso-8859-1\\"
Content-Transfer-Encoding: 7bit
{$body_plain}
--PHP-alt-{$hash}
Content-Type: text/html; charset=\\"iso-8859-1\\"
{$body_html}
--PHP-alt-{$hash}--\
";

if ($has_attachment)	{

	$body .= "
--{$hash}
Content-Type: {$fileatt_type};
name=\\"{$fileatt_name}\\"
Content-Disposition: attachment;
filename=\\"{$fileatt_name}\\"
Content-Transfer-Encoding: base64\
\

{$data}\
\

--{$hash}--\
";
	
	}

//echo $body_html;

mail($email, $subject, $body, join("\\r\
", $head));
	

Now as long as I do not add an attachment the emails work flawlessly but when I add an attachment the email comes in showing the plain text version, then the html version and has no attachment?

Need another set of eyes here, what the heck am I doing wrong?

thanks

Its easier if you use phpMailer.

Do you divide up the base64 encoded data? If not use chunk_split on the data.
Also why do you have a boundary after the file? it is not needed, the double
is not needed either.

Your also missing a content transfer encoding on the html header.

If that dont work, you can verify that your file info variables contain correct info ($fileatt_type, $fileatt_name)