emailing html attachment loses image map

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mjorld
Forum Newbie
Posts: 5
Joined: Mon Apr 19, 2010 10:28 am

emailing html attachment loses image map

Post by mjorld »

I am loving this forum. It seems I can find answers to nearly all my php question. Unfortunately here is one of the reasons I have to say "nearly".

I have built a small program that builds an html file which is to be used as an email signature. The user fills out a simple form and receives an email that contains the html signature. The signature contains an image map with hot spots like twitter, facebook etc. The problem is that when the user receives the email, the hotspots are gone. The file created has them just fine, so it must be something to do with the encoding of the email.

Here is what I am doing:

// create the signature
$sig = ob_get_clean();

$fp = fopen( "mysig.html", "w" );
fwrite( $fp, $sig );
fclose( $fp );

$fileatt = "mysig.html"; // Path to the file
$fileatt_type = "application/octet-stream"; // File Type
$fileatt_name = "signature"; // Filename that will be used for the file as the attachment

$email_from = "signature maker"; // Who the email is from
$email_subject = "Your new email signature"; // The Subject of the email
$email_txt = "Here is your new signature"; // Message that the email has in it

$headers = "From: ".$email_from;

$file = fopen($fileatt,'rb');
$data = fread($file,filesize($fileatt));
fclose($file);

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";

$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";

$ok = @mail($email, $email_subject, $email_message, $headers);

I have fiddled around with various different options of the encoding but had no success. If anyone has seen this before or knows the solution, please enlighten me. It would be most appreciated.
Thx.
Post Reply