Home
HomeFlexible, Lightweight and Truly Skinnable Flash ComponentsPHPObject and other Flash ExtensionsForumsBlog JournalLinks
Buy Flash Components
  PHPObject - Opensource PHP Flash Remoting

redhand Using HTMLMimeMail with PHPObject

Author
GhostWire Studios


Overview
In this tutorial, we are going to use Richard Heye's htmlMimeMail PHP class in Flash, without making any modification to the PHP class. You can download the class from phpguru.org. The htmlMimeMail PHP class originally allows PHP developers to send emails (both HTML and/or plain text) from their PHP scripts. It also allows attachments etc. In this tutorial, we will use the class to send out a simple email from Flash.


Step One (Installing PHPObject):
We assume you already have the PHPObject library installed. Read Installing PHPObject if you have not done so.


Step Two (Uploading htmlMimeMail class):
Unpack the htmlMimeMail class 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 the visuals in Flash):
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 (Code the Flash application):
The following shows the actionscript you should enter in the actions panel:


// 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 go! Running the movie now executes the htmlMimeMail class on your server and sends out the email. Of course, you should consider modifying the actionscript above to suit your application; it is quite useless to have a movie sending 'Test Message' automatically everytime you run it. So go ahead now and starting building a rich internet email client:
- build your textfields for collecting user input (recipients addresses, subject, message, etc.)
- build the buttons to react to user input, and subsequently 'invoke the php class methods in a batch, sequentially'
- build the visual assets and make it beautiful

Most importantly, have fun!


About PHPObject

PHPObject is an opensource alternative to Flash Remoting for PHP developers. With PHPObject, you can call a method of a PHP class/library on your web server as if the class/library was defined in Flash itself. It takes care of your client-server connections and makes passing of variables (properties) between Flash MX and PHP easy, and thereby providing a convenient way to connect rich media clients with data and business logic residing on your server.

PHPObject is developed by GhostWire Studios and released under the GNU LGPL.


>> Documentation <<

 
Contact UsSite Map
Copyright © 2003-2006 GhostWire Studios