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@email.com"; 
	$subject = "From ".$email; 
	$sent = mail($to, $subject); 
	if($sent) {
		return 1;
	}
	else {
		return 0;
	}
}

 

thank you for any help !

Link to comment
Share on other sites

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;
	}
}
}

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.