Jump to content

Error in my small php email code (also using flash)


coogie

Recommended Posts

Hello there, i've struggled with this for a week now and simply cannot identify the problem.

 

I have a simple email form in flash cs3 and 2 php scripts. For some reason, i am getting this error in flash "Error #2101: The String passed to URLVariables.decode() must be a URL-encoded query string containing name/value pairs". I'm pretty sure it is not an error in my flash, because i've used the exact some code with another php script and it works.

 

Here is my php. Please help me find an error in it?

 

feedback.php

<?php

    //@require_once ('database.php');
    @require_once ('function.php');

    if(isset($_POST['varEmail']) && isset($_POST['varMessage'])) {
    
            if(isValidatedEmail($_POST['varEmail'])) {
            
                        if(feedbackform($_POST['varEmail'], $_POST['varMessage'])) {
                            echo "feedback=success";
                        } else {
                                echo "feedback=failed";
                        }
                        
            } else {
            
            echo "feedback=invalidemail";
        
            }
        
        }
        
?>

 

inside function.php

function isValidatedEmail($email) {
            
            if (!ereg("[^@]{1,64}@[^@]{1,255}", $email)) {
                return false;
            }
            
            $email_array = explode("@", $email);
            $local_array = explode(".", $email_array[0]);
                    
                    for ($i = 0; $i < sizeof($local_array); $i++) {
                        if (!ereg("^(([a-za-z0-9!#$%&*+/=?^_`{|}~-][a-za-z0-9!#$%&*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) {
                            return false;
                        }
                    }
                    
                    
            if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) {
                $domain_array = explode(".", $email_array[1]);
                    
                    if (sizeof($domain_array) < 2) {
                        return false;
                    }
                    
                    for ($i = 0; $i < sizeof($domain_array); $i++) {
                        if (!ereg("^(([a-za-z0-9][a-za-z0-9-]{0,61}[a-za-z0-9])|([a-za-z0-9]+))$", $domain_array[$i])) {
                            return false;
                        }
                    }
                    
            }
            
        return true;
}

function feedbackform($email, $message) {
	$to = "[email protected]"; 
	$subject = "From ".$email; 
	$sent = mail($to, $subject); 
	if($sent) {
		return 1;
	}
	else {
		return 0;
	}
}

 

thank you for any help !

I know its not a flash forum but thought i'd post my flash function that calls the script :)

function contact():void {
var theVariables:URLVariables = new URLVariables();

theVariables.varEmail = email.text;
theVariables.varMessage = commentstxt.text;

var theRequest:URLRequest = new URLRequest();
theRequest.url = "feedback.php";
theRequest.method = URLRequestMethod.POST;
theRequest.data = theVariables;

var theLoader:URLLoader = new URLLoader();
theLoader.dataFormat = URLLoaderDataFormat.VARIABLES;
theLoader.addEventListener(Event.COMPLETE, loadCompleteHandler);
theLoader.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
theLoader.load(theRequest);

function handleIOError(event:IOErrorEvent):void	{
	event.target.removeEventListener(IOErrorEvent.IO_ERROR, handleIOError);
}	


	function loadCompleteHandler(event:Event):void {
	switch(event.target.data.feedback) {
		case "success":
			howmuch.text = "Sent successfully"
			initialContact();
			break;
		case "invalidemail":
			howmuch.text = "Please use a valid email address.";
			break;
		case "failed":
			howmuch.text = "Error sending"
			break;
		default:
			return;
	}
}
}

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.