Solved

email richtext message with php mail() function

Posted on 2003-12-05
5
1,214 Views
Last Modified: 2008-03-17
I would like to know how to send a message as a richtext message using php mail() function?

I went through a few examples but all of them use rtf as attachments. Is it possible to email richtext without attaching a rtf document?

I use php 4.1.2 on a linux redhat 7.3 system with apache 1.3 as my webserver.

I tried the email as follows:

$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-Type: text/richtext\r\n";
$subject  = "test";
$message = "testing rtf email"."\n";
$message.= "testing <b>BOLD</b>"."\n";
$message.= "testing <bold>BOLD</bold>"."\n";
$email = "me@localhost";
mail($email, $subject, $message, $headers);

none of this seemed to work.
Any help please?
0
Comment
Question by:louwtjie
  • 2
  • 2
5 Comments
 
LVL 6

Expert Comment

by:aolXFT
ID: 9883218
Rich Text Emails are usually sent using HTML.

try

$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-Type: text/html\r\n";
$subject  = "test";
$message = <<<EOF
<html>
<body>
<h1>Testing HTML Email</h1>
<p>This should be html Email, demonstrating <b>bold</b> <i>Italics</i>, and <u>underline</u></p>
</body>
</html>
EOF;
$email = "me@localhost";
mail($email, $subject, $message, $headers);

I haven't tested this, but it's
0
 
LVL 1

Author Comment

by:louwtjie
ID: 9894799
Yes, but I don't want to send it in html format. Is there a way to send it without html?
0
 
LVL 2

Expert Comment

by:wise0ne
ID: 9894842
<?php
// the preceding part of the mail remains as same as that of a normal
// mail.

fputs($fd, "Content-Type: multipart/mixed; boundary=$boundry nn");
fputs($fd, "Content-Transfer-Encoding: 7bit n");
fputs($fd, "This is a multi-part message in MIME format nn");
fputs($fd, "--$boundry n");
fputs($fd, "Content-type: text/plain; charset=us-ascii n");
fputs($fd, "Content-Transfer-Encoding: 7bit n");
fputs($fd, "n");
fputs($fd, " message is thisn"); // message goes here
fputs($fd, "--$boundry n");

fputs($fd, "Content-type: application/rtf; charset=us-ascii n");
fputs($fd, "Content-Transfer-Encoding: 7bit n");
fputs($fd, "Content-Disposition: inline; filename=\"mailer.rtf\" n");
fputs($fd, "Content-Base: \"file///c|/temp/mailer.rtf\" rnrn");

// the succeeding part of the mail remains as same as that of a normal
// mail.

?>

Article Link : http://www.php9.com/index.php/section/articles/name/Using%20PHP%20for%20Rich%20Text%20Format%20RTF



HTH
0
 
LVL 6

Accepted Solution

by:
aolXFT earned 250 total points
ID: 9906537
If you want to send the message in RTF, then you are going to have to write the message in RTF.

From two lines of your code, it looks like you are using some sort of SGML.

$message.= "testing <b>BOLD</b>"."\n";
$message.= "testing <bold>BOLD</bold>"."\n";

Where you use <tag>'s to identify how everything looks.

If you want to write your message using <tag>'s (ie using some sort of SGML), but want to send it as RTF, you are going to have to use(and probably write) a converter from your format to RTF, and integrate it with your app.

I say some sort of SGML, because while <b> is a valid html tag, I don't believe <bold> is one.

Why don't you want to use HTML?
0
 
LVL 1

Author Comment

by:louwtjie
ID: 9910140
The reason I don't want to use HTML is that some older mail agents can't handle HTML. Most of them can handle rtf though.
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Introduction Many web sites contain image galleries; a common design for these galleries includes a page with a collection of thumbnail images.  You can click on each of the thumbnail images to see the larger version of the image.  This is easily i…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now