Send richtext mail can't be read by receiver
Posted: Sun Aug 31, 2008 3:33 am
I'm newbie in PHP..
I've problem with my mail code.
I develop send mass mail facility where the text i want to send is in richtext format. I used tinymce as WYSIWYG editor. The content type i use is text/richtext, is it possible?.
When the message is sent, the receiver can't read the message in correctly format. But when i use text/html content type, message can be read, but the format is not as well as i sent. E.g: when i typed text in right alignment, in receiver didn't show up as right alignment, but left alignment. Any idea?.
The code i used:
$to=$_POST['txtto'];
$cc=$_POST['txtcc'];
if(!empty($cc))
$to.=$cc;
$subject=$_POST['txtsubject'];
$content=$_POST['txtcontent'];
// Obtain file upload vars
$file_attachment= $_FILES['file_attachment']['tmp_name'];
$file_attachment_type=$_FILES['file_attachment']['type'];
$file_attachment_name=$_FILES['file_attachment']['name'];
$site=get_option('site_title');
$from=$user_fullname." \<".$cur_user_email."\> - ".$site;
$headers="From: $from \r\n";
if(is_uploaded_file($file_attachment))
{
// Read the file to attached ('rb' = read binary)
$file=fopen($file_attachment, 'rb');
$data=fread($file, filesize($file_attachment));
fclose($file);
// Generate a boundary string
$semi_rand=md5(time());
$mime_boundary="==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "MIME-Version: 1.0\n".
"Content-Type: multipart/mixed;\n".
" boundary=\"{$mime_boundary}\"";
// Add multipart boundary above the richtext message
$content =
"--{$mime_boundary}\n".
"Content-Type: text/richtext charset=\"iso-8859-1\"\n".
"Content-Transfer-Encoding: 8bit\n\n".
$content."\n\n";
// Base 64 encode the file data
$data=chunk_split(base64_encode($data));
// Add file attachment to the message
$content .= "--{$mime_boundary}\n".
"Content-Type:{$file_attachment_type};\n".
" name=\"{$file_attachment_name}\"\n".
"Content-Disposition: attachment;\n".
" filename=\"{$file_attachment_name}\"\n".
"Content-Transfer-Encoding: base64\n\n".
$data."\n\n".
"--{$mime_boundary}--\n";
}
// Send the message
// Make an archive, sent it own email
//$to.=", $cur_user_email";
$sent=@mail($to, $subject, $content, $headers);
So, is't possible to sent mail in richtext format as what it used in tinymce editor?, without convert it to html format?....
Anybody can help me?...
Thank's.
I've problem with my mail code.
I develop send mass mail facility where the text i want to send is in richtext format. I used tinymce as WYSIWYG editor. The content type i use is text/richtext, is it possible?.
When the message is sent, the receiver can't read the message in correctly format. But when i use text/html content type, message can be read, but the format is not as well as i sent. E.g: when i typed text in right alignment, in receiver didn't show up as right alignment, but left alignment. Any idea?.
The code i used:
$to=$_POST['txtto'];
$cc=$_POST['txtcc'];
if(!empty($cc))
$to.=$cc;
$subject=$_POST['txtsubject'];
$content=$_POST['txtcontent'];
// Obtain file upload vars
$file_attachment= $_FILES['file_attachment']['tmp_name'];
$file_attachment_type=$_FILES['file_attachment']['type'];
$file_attachment_name=$_FILES['file_attachment']['name'];
$site=get_option('site_title');
$from=$user_fullname." \<".$cur_user_email."\> - ".$site;
$headers="From: $from \r\n";
if(is_uploaded_file($file_attachment))
{
// Read the file to attached ('rb' = read binary)
$file=fopen($file_attachment, 'rb');
$data=fread($file, filesize($file_attachment));
fclose($file);
// Generate a boundary string
$semi_rand=md5(time());
$mime_boundary="==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "MIME-Version: 1.0\n".
"Content-Type: multipart/mixed;\n".
" boundary=\"{$mime_boundary}\"";
// Add multipart boundary above the richtext message
$content =
"--{$mime_boundary}\n".
"Content-Type: text/richtext charset=\"iso-8859-1\"\n".
"Content-Transfer-Encoding: 8bit\n\n".
$content."\n\n";
// Base 64 encode the file data
$data=chunk_split(base64_encode($data));
// Add file attachment to the message
$content .= "--{$mime_boundary}\n".
"Content-Type:{$file_attachment_type};\n".
" name=\"{$file_attachment_name}\"\n".
"Content-Disposition: attachment;\n".
" filename=\"{$file_attachment_name}\"\n".
"Content-Transfer-Encoding: base64\n\n".
$data."\n\n".
"--{$mime_boundary}--\n";
}
// Send the message
// Make an archive, sent it own email
//$to.=", $cur_user_email";
$sent=@mail($to, $subject, $content, $headers);
So, is't possible to sent mail in richtext format as what it used in tinymce editor?, without convert it to html format?....
Anybody can help me?...
Thank's.