Solved

email richtext message with php mail() function

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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…
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 …

740 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