This page is no longer updated - please visit http://ghostwire.com Thank you!
 

« PHPObject »
An Opensource Alternative to Flash Remoting
Current Release
Readme
Notes
Journal
Archives

Notes
Friday May 02, 2003

Tutorial: Using htmlMimeMail

It has been a while since I released PHPObject. The examples distributed with PHPObject are pretty simple. I haven't written any tutorial on the use of PHPObject with PHP classes (well, I had hoped one of you would). I did a tutorial on webservices (Google Web API) earlier on. The truth is I haven't really thought of any good tutorial idea. I still think that the usage/syntax is pretty straight forward. I have designed the library such that it should be able to use any of your existing PHP classes with no modification.

Nevertheless, now that I am done with v1.4, I have decided to write a little tutorial. I realized that this will serve both as a demonstration as well as a proof of concept.

In this tutorial, I am going to use Richard Heye's htmlMimeMail PHP class. You can download the class from phpguru.org. The class is not available on GhostWire because I would like to show you that the PHP class downloaded from phpguru.org can be used without modification.

The htmlMimeMail PHP class originally allows PHP developers to send HTML/plain text emails from their PHP scripts. It also allows attachments etc. In this tutorial, we will use the class to send out a simple email.

Step One:
Unpack the PHPObject distribution file (zip file), and run the .mxp installer (if you haven't done so already) and upload the Gateway.php to your server.

Step Two:
Download htmlMimeMail PHP class from phpguru.org. Unpack the distribution and upload the files to your server (same directory as Gateway.php, or your designated classdir). Actually, only two files from the distribution are required in this tutorial - htmlMimeMail.php and mimePart.php.

Step Three:
Build your Flash MX application look-and-feel. Well, this isn't a tutorial on Flash design, so I won't elaborate here. Anyway, this step is optional in this tutorial. You can leave the stage empty.

Step Four:
Start coding:

// import the library
#include "PHPObject.as"

// set up gateway url and key
_global.defaultGatewayUrl = "http://mydomain.com/services/Gateway.php";
_global.defaultGatewayKey = "secret";

// creates the object, pass a third parameter to switch off retrieval of remote object's properties
myObj = new PHPObject("htmlMimeMail","",1);

// create an array containing list of recipients of the email you are going to send
// the 'send()' method of the htmlMimeMail class takes in an array

var emails = ["email1@domain.com","email2@domain.com"];

// prepare the html and plain text versions of the message
var htmlmsg = "<b>Test</b> <i>Message</i>";
var textmsg = "Test Message";

// set up responder
// the last method to be invoked in the batch below is 'send()'
// the method 'send()' returns either true of false

myObj.send_onResult = function(result) {
    if (result) {
        // success
    } else {
        // failed
    }
}

// invoke the php class methods in a batch, sequentially
myObj.delayExecute();
myObj.setHtml(htmlmsg, textmsg, './');
myObj.setFrom("YourName ");
myObj.setSubject("Test Subject");
myObj.send(emails);
myObj.execute();

There! You are done! Running this movie will trigger the remote methods. Of course, the htmlMimeMail class can do more than the above demonstrates. You can for example attach a file to your email (the file has to be on your server already). Now is up to you to implement those features in your own application :)

Posted by sunny at May 2, 2003 12:12 PM

 

Comments

gooooooooooood

Posted by: mahmoud at May 5, 2003 02:21 PM

vbcxbc

Posted by: bv at May 8, 2003 02:47 PM

Great example.

Combined with another PHP class for file upload and a corresponding Flash bit, you can have a complete email system from a flash page. Except the viewing of recieved mails - I guess!

Does anyone know of a PHP class/file to allow reading of a mailbox (ie server side tool for doing FRM (or somesuch) on Linux)?

PHPObject is one of the best things to come out in a long while for Flash and I think everyone should be using it.

Posted by: Zingo at May 11, 2003 07:08 PM

Here is a great resource to find PHP classes
http://www.phpclasses.org/browse.html/browse.html

Posted by: sunny at May 14, 2003 12:03 PM

 


Zones



Forums