A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: sending e-mail

  1. #1
    Junior Member
    Join Date
    Aug 2007
    Posts
    6

    sending e-mail

    Hi,

    I've been looking through many tutorials on how to make a contact form, which sends e-mail directly to me whenever someone types stuff in it and clicks 'Submit'. Unfortunately, most of these tutorials are for AS2, and therefore don't work in AS3, so I've tried to modify the code with the limited AS3 knowledge that I have, and this is what I got:

    Code:
    import flash.text.TextField;
    
    var msgsent;
    	var missing;
    	msgsent.visible = false;
    	missing.visible = false;
    	var addr;
    	addr.visible = false;
    	var contact_php_file = "flashEmailer.php";
    	var n;
    	var e;
    	var m;
    	
    send_btn.addEventListener(MouseEvent.MOUSE_DOWN, checkForm);
    	
    	function validateEmail(address) {
    		// Check address length
    		if (address.length>=7) {
    			// Check for an @ sign
    			if (address.indexOf("@")>0) {
    				// Check for at least 2 characters following the @
    				if ((address.indexOf("@")+2)<address.lastIndexOf(".")) {
    					// Check for a domain name of at least 2 characters
    					if (address.lastIndexOf(".")<(address.length-2)) {
    						// If all the above tests pass, the email address is in valid format
    						return true;
    					}
    				}
    			}
    		}
    		// Called if the email fails 
    		return false;
    	}
    	
    	function checkForm() {
    		n = form.name_txt.text;
    		e = form.email_txt.text;
    		m = form.msg_txt.text;
    		if (m != "" && e != "" && validateEmail(e)) {
    		sendEmail(n,e,m);
    		} else {
    			gotoAndStop(5);
    		}
    	}
    	
    	function sendEmail(n, e, m) {
    		var session;
    		session = "?nocache="+Math.random();
    		var contact_lv = new URLLoader();
    		contact_lv.name = n;
    		contact_lv.email = e;
    		contact_lv.message = m;
    		contact_lv.key = "email";
    		trace(n+" - "+e+" - "+m);
    		contact_lv.load(contact_php_file+session,contact_lv,"POST");
    		contact_lv.onLoad = function(success) {
    			if (!success) {
    				return trace("Error calling PHP File!");
    			} else {
    				gotoAndPlay(10);
    			}
    		}
    		trace("did it work?");
    	}
    	
    	stop();
    The compiler doesn't complain, so I assumed it would do SOMETHING, but after my movie loaded and I went to my contact us section, this came up in the output (without me typing anything in the text fields or clicking submit):

    TypeError: Error #1010: A term is undefined and has no properties.
    at sushisho_fla::email_36/sushisho_fla::frame1()

    I checked line 36 and all it is is the variable declaration for name:

    Code:
    Line 36: n = form.name_txt.text;
    I am absolutely stumped. Anyone?

  2. #2
    Multitouch Aficionado
    Join Date
    Mar 2006
    Posts
    275
    Problems:
    -Initialize your variables
    -checkForm(...args). The ...args gives the received event a place to live, but lets you call checkForm() from other places if you need to.
    -URLLoader should be URLVariables. Read the AS3 LiveDocs for more about sending data to a script.

    Code:
    var msgsent:Object = new Object();
    	var missing:Object = new Object();
    	var addr:Object = new Object();
    	msgsent.visible = false;
    	missing.visible = false;
    	addr.visible = false;
    	var contact_php_file = "flashEmailer.php";
    	var n:String;
    	var e:String;
    	var m:String;
    Code:
    function checkForm(...args) {
    		n = form.name_txt.text;
    		e = form.email_txt.text;
    		m = form.msg_txt.text;
    		if (m != "" && e != "" && validateEmail(e)) {
    		sendEmail(n,e,m);
    		} else {
    			gotoAndStop(5);
    		}
    	}
    Code:
    		var contact_lv = new URLVariables();
    		contact_lv.name = n;
    		contact_lv.email = e;
    		contact_lv.message = m;
    		contact_lv.key = "email";

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center