I can get my mime messages to send and display what I want it to. The problem now, however, is that the image appears at the top in the html, the html appears, then the attachment again appears, so I've got a top and bottom image, but I only want the bottom image.
Here's how the code arrives, two pictures, and I only want the top on to be in place.
<all the regular stuff>
To: jabberjaws@******.net
Subject: Sample
From: <chowderhead@*****.com>
MIME-Version: 1.0
Content-Type: multipart/mixed;
boundary="==Boundary_x55a5c19294408203a473c3b935d9c923x"
--==Boundary_x55a5c19294408203a473c3b935d9c923x
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<html><head></head><body><font face="arial"><img src="cid:2fdbf1bcc735becc9390480033b1aba9"><br><br><br>
<br></FONT></body></html>
--==Boundary_x55a5c19294408203a473c3b935d9c923x
Content-Type: image/jpg; name="email_image.jpg"
Content-ID: <2fdbf1bcc735becc9390480033b1aba9>
Content-Disposition: inline;
filename="email_image.jpg"
Content-Transfer-Encoding: base64
/9j/-----/Z/
--==Boundary_x55a5c19294408203a473c3b935d9c923x--
Here is the code I've written to get to this stage.
$headers = "From: -----------------"
$to = 'user@******';
//$to = '$mail';
$subject = $_SESSION['subject'];
$img_id= md5(time()*time());
$message0html = "Dear $firstname, <br><br>";
$html ="<img src=\"cid:" . $img_id . "\"><br><br>";
$html .= $message0html;
$html .= " ";
$html .= $phtml;
$html .= "<br><br></FONT></body></html>";
//the below is your own plain text message (all the $message(x))
$message0 = $message0text;
$message1 = $ptext;
//first file to attach
$fileatt2 = '../images/email_image.jpg';//put the relative path to the file here on your server
$fileatt_name2 = 'email_image.jpg';//just the name of the file here
$fileatt_type2 = filetype($fileatt2);
$file2 = fopen($fileatt2,'rb');
$data2 = fread($file2,filesize($fileatt2));
fclose($file2);
$semi_rand = md5(time());
$mime_boundary = "==Boundary_x{$semi_rand}x";
$message = "--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
"<html><head></head><body><font face=\"arial\">" .
$html."\r\n\n";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Base64 encode the file data
$data2 = chunk_split(base64_encode($data2));
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: image/jpg; name=\"{$fileatt_name2}\"\n" .
"Content-ID: <" . $img_id . ">\n" .
"Content-Disposition: inline; \n" .
" filename=\"email_image.jpg\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data2 . "\n\n" .
"--{$mime_boundary}--\n";
// Send the message
$send = mail($to, $subject, $message, $headers);
if ($send) {
echo "<p>Email Sent to intended recipients successfully!</p>";
} else {
echo "<p>Mail could not be sent. You missed something in the script. Sorry!</p>";
}
?>
I've replaced all the \n with \r\n to no avail. This is so close to being complete, but it is so far away. I'm out of ideas.
Thanks for your help.