Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Emailer Class (for PHP) (See related posts)

   1  
   2  import mx.events.EventDispatcher;
   3  import mx.utils.Delegate;
   4  
   5  class Emailer {
   6  	
   7  	// required for EventDispatcher:
   8  	public var addEventListener:Function;
   9  	public var removeEventListener:Function;
  10  	private var dispatchEvent:Function;
  11  	
  12  	// use to communicate with php script
  13  	private var _lv:LoadVars;
  14  	// holds address of sender
  15  	private var _sentFrom:String;
  16  	
  17  	// constructor
  18  	public function Emailer() {    
  19  		EventDispatcher.initialize(this);
  20  		_lv = new LoadVars();
  21  	}
  22  
  23  	// 
  24  	private function dataReceived(dataxfer_ok:Boolean):Void {
  25  		// if some problem with loadVars transfer, pass back error=2
  26  		if (!dataxfer_ok) dispatchEvent({target:this, type:'mailSent', errorFlag:2});
  27  		// otherwise pass back error code returned from script
  28  		else dispatchEvent({target:this, type:'mailSent', errorFlag:Number(_lv["faultCode"])});
  29  	}
  30  	
  31  	 // Use loadvars object to send data (set to call dataReceived when script returns data)
  32  	public function sendEmail(sub:String, fn:String, fe:String, msg:String, rep:String):Void {
  33  		// if user already sent from this address, show error msg
  34  		if (_sentFrom == fe) dataReceived(false);
  35  		// otherwise set up and send
  36  		else {
  37  			_sentFrom = fe;
  38  			// specify function to handle results, make scope = Emailer
  39  			_lv.onLoad = Delegate.create(this, dataReceived);
  40  			// set up properties of lv to items to be POSTed
  41  			_lv.subject = sub;
  42  			_lv.name = fn;
  43  			_lv.email = fe;
  44  			_lv.message = msg;
  45  			_lv.reply = rep;
  46  			// call script
  47  			_lv.sendAndLoad("sendemail.php", _lv, "POST");
  48  		}
  49  	}
  50  } 

You need to create an account or log in to post comments to this site.


Click here to browse all 5349 code snippets

Related Posts