PHPBuilder - Using PHP for RTF Page 4

# Using PHP for RTF - Page 4

by: Sujith Nair
|
May 22, 2002

Another alternative for defining the scope is by closing the control with a '0'. That is, when such a control word (like \b) has no parameter or has a nonzero parameter (like \b1), it is assumed that the control word turns on the property. When such a control word has a parameter of 0 (like \b0), it is assumed that the control word turns off the property. For example, \b turns on bold, whereas \b0 turns off bold. It's not over yet. The most important part is, we have to take care of all the "\n", "\r" and "\t"s in the document. Best way to deal with it is to escape all "\"s preceding 'r','n' and 't' before writing to a file. For newlines we can make use of "\par".
Now I was left with only one thing: to send email attachment of RTF files. After I was able to write an RTF file, it didn't seem difficult. All I did was define a Content-Type of "multipart/mixed" as parent, "text/plain" for message and "text/rtf" for the attachment. I will show you how.
``` <?php // the preceding part of the mail remains as same as that of a normal // mail. fputs(\$fd, "Content-Type: multipart/mixed; boundary=\$boundry \n\n"); fputs(\$fd, "Content-Transfer-Encoding: 7bit \n"); fputs(\$fd, "This is a multi-part message in MIME format \n\n"); 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 this\n"); // 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\" \r\n\r\n"); // the succeeding part of the mail remains as same as that of a normal // mail. ?> ```

Comment and Contribute

## Your comment has been submitted and is pending approval.

Author:
Sujith Nair

Comment:

Comment:

(Maximum characters: 1200). You have characters left.