Solved

email richtext message with php mail() function

Posted on 2003-12-05
5
1,279 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

685 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