How do I attach a .gif in an email and make it appear in the message part of the email?
I currently have this function:
function sendEmail($to,$subject,$message,$from,$fromAddress) {
if(($from == "") AND ($fromAddress == "")) {
$from = "Onlyfinebeer";
$fromAddress = "gavin@onlyfinebeer.co.uk";
}
$boundary = "bound-".md5(uniqid (rand()));
$fp = fopen("../images/logoOnlyfinebeerEmail.gif","r");
$image = fread($fp, filesize($image));
$image = base64_encode($image);
$image = chunk_split($image);
// Headers
$headers = "From: \"".$from."\"<".$fromAddress.">\n";
$headers .= "Reply-To: ".$fromAddress."\n";
$headers .= "X-Mailer: PHP/".phpversion()."\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative;\n\tboundary=\"".$boundary."\";\n\n";
// Plain Message
$plainMessage = "--".$boundary."\n";
$plainMessage .= "Content-Type: text/plain;\n";
$plainMessage .= "charset=\"iso-8859-1\"\n";
$plainMessage .= "Content-Transfer-Encoding: 7bit\n\n";
$plainMessage .= strip_tags(eregi_replace("<br>","\n",$message));
$plainMessage .= "\n\n--".$boundary."\n";
// HTML Message
$htmlMessage = "Content-Type: text/html;\n";
$htmlMessage .= "charset=\"iso-8859-1\"\n";
$htmlMessage .= "Content-Transfer-Encoding: 7bit\n\n";
$htmlMessage .= "<body><font face=\"verdana\" size=\"-1\">\n";
$htmlMessage .= "<img src=\"logoOnlyfinebeerEmail.gif\" alt=\"Onlyfinebeer\"><p>\n";
$htmlMessage .= stripslashes(eregi_replace("\n","<br>",$message));
$htmlMessage .= "</font></body>\n\n";
$htmlMessage .= "--".$boundary."\n";
// Image Attachment
$attachment = "Content-Type: image/gif;\n";
$attachment .= "filename=\"logoOnlyfinebeerEmail.gif\"\n";
$attachment .= "Content-Transfer-Encoding: base64\n";
$attachment .= "Content-Disposition: inline\n\n";
$attachment .= $image;
$attachment .= "\n\n--".$boundary."--";
$message = $plainMessage.$htmlMessage.$attachment;
mail($to,$subject,$message,$headers);
}
Nothing appears in the source of the email where the encoded image should be.
Cheers,
Tony.