Hello. The issue I am having occurs upon the receipt of the email message. I can get the MIME message to have either the picture and no text OR text OR just text with the HTML tags listed on it. I need it to have the image at the top (it is properly attached) and the html verbage.
I have searched the MIME docs painfully and cannot find the errors in my code. Can you please assist?
Again, the issue is properly constructing the message so that it displays properly in an email client.
Here is the short version of the code when viewed as "Source" from the browser window.
To: [email]user@comcast.net[/email]
Subject: sample subject
From: [email]test@testsite.net[/email]
MIME-Version: 1.0
Content-Type: multipart/alternative;
boundary="==Multipart_Boundary_x480fc0fd8b042f6d6939cfc9af0015d1x"
Content-Type: multipart/mixed;
--==Multipart_Boundary_x480fc0fd8b042f6d6939cfc9af0015d1x
Content-Type: text/html; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
<font face=Arial><img src='email_image.jpg'><br><br><br />
</body></html>
--==Multipart_Boundary_x480fc0fd8b042f6d6939cfc9af0015d1x
Content-Type: text/plain; charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
text
--==Multipart_Boundary_x480fc0fd8b042f6d6939cfc9af0015d1x
Content-Type: image/jpeg;
name="email_image.jpg"
Content-Disposition: inline;
filename="email_image.jpg"
Content-Transfer-Encoding: base64
/9j/ Data for included jpg file//Z
--==Multipart_Boundary_x480fc0fd8b042f6d6939cfc9af0015d1x--
and the actual code:
$headers = "From: user@comcast.net";//put you own stuff here or use a variable
$to = '$email';
$subject = $_SESSION['subject'];
//make up your own html or use an include
if ($firstname!=""){
$message0html = "Dear $firstname, <br><br>";
$message0text = "Dear $firstname, \n\n";
}
else {
$message0html = 'Dear member,<br><br>' ;
$message0text = 'Dear member,\n\n' ;
}
$html ="<img src='email_image.jpg'><br><br>" . $message0html;
$html .= "</body></html>";
//the below is your own plain text message (all the $message(x))
$ptext = "just text";
// attachments
$att_file = '../images/email_image.jpg';
$att_file_name = 'email_image.jpg';
$att_file_type = filetype($att_file);
$input_file = fopen($att_file,'rb');
$data_read = fread($input_file,filesize($att_file));
fclose($input_file);
// Generate a boundary string that is unique
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/alternative;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "--{$mime_boundary}\n" .
"Content-Type: text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
"<font face=Arial>" .
$html."\r\n";
$message .= "--{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message0text . "\n\n" .
$ptext . "\n\n";
// Add the headers for a file attachment
$headers .= "\nContent-Type: multipart/mixed;\n";
//" boundary=\"{$mime_boundary}\"";
// Base64 encode the file data
$data_read = chunk_split(base64_encode($data_read));
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: image/jpeg;\n" . // {$fileatt_type}
" name=\"{$att_file_name}\"\n" .
"Content-Disposition: inline;\n" .
" filename=\"{$att_file_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data_read . "\n\n" .
"--{$mime_boundary}--\n";
// Send the message
$send = mail($to, $subject, $message, $headers);
if ($send) {
echo "<p>Email Sent to " . $firstname ." recipients successfully!</p>";
} else {
echo "<p>Mail could not be sent. You missed something in the script. Sorry!</p>";
}
?>