Solved

email richtext message with php mail() function

Posted on 2003-12-05
5
1,316 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Don't Cry: How Liquid Web is Ensuring Security

WannaCry is just the start. Read how Liquid Web is protecting itself and its customers against new threats.

Question has a verified solution.

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

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

729 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