?
Solved

email richtext message with php mail() function

Posted on 2003-12-05
5
Medium Priority
?
1,405 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 500 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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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.
Suggested Courses

719 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