Hello.
I have been trying to get an email form to work for quite a while now.
This is the code and it doesn’t seem to work. (you can see an example here http://refreshed.ee/email/email2.html).
The fla:
var validmail:uint = 0;
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("http://refreshed.ee/email/sendEmail.php");
var varLoader:URLLoader = new URLLoader;
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
submit_btn.addEventListener(MouseEvent.CLICK, sendActions);
varLoader.addEventListener(Event.COMPLETE, loadComplete);
function textArea(parameter:String) {
var myText:TextField = new TextField();
myText.text = parameter;
this.addChild(myText);
}
textArea("this is a parameter");
function sendActions(event:MouseEvent):void {
if ((fname_txt.text != "" || subject_txt.text != "Required")
&& email_txt.text != "" && (subject_txt.text != "" || subject_txt.text != "Required") ) {
// Check to make sure the email address includes and @.
var textLength:Number = email_txt.text.length;
for (var i:Number = 0; i < textLength; i++) {
if (email_txt.text.substr(i, 1) == "@") {
this.validmail = 1;
break;
}
}
}
if (this.validmail == 0) {
this.gotoAndStop(2);
} else {
variables.key = "pass";//security code
variables.subject = subject_txt.text;
variables.fname = fname_txt.text;
variables.email = email_txt.text;
variables.comments = comments_txt.text;
varLoader.load(varSend);
}
}
function loadComplete (event:Event)
{
var loader:URLLoader = URLLoader(event.target);
trace ("completeHandler: " + loader.data);
if (loader.data != "&reply=error") {
//if (vars.reply != "error") {
this.gotoAndStop (3);
} else {
this.gotoAndStop (2);
}
}
fname_txt.tabIndex = 2;
subject_txt.tabIndex = 3;
email_txt.tabIndex = 4;
comments_txt.tabIndex = 5;
submit_btn.tabIndex = 6;
this.stop ();
the php:
<?
if(isset($_POST['fname'])){$fname = stripslashes($_POST['fname']);}
else {$error .= "Your Name seems to be missing!";}
if(isset($_POST['subject'])){$subject = stripslashes($_POST['subject']);}
else {$error .= "your subject seems to be missing!";}
if(isset($_POST['email'])){$email = stripslashes($_POST['email']);}
else {$error .= "your email seems to be missing!";}
if(isset($_POST['comments'])){$comments = stripslashes($_POST['comments']);}
else {$error .= "The comments of your email seems to be missing!";}
if ($_POST['key'] == "pass") {
$to = "s.herkyl@gmail.com";
$subject = "{$_POST['subject']}";
$message = "Sent From http://www.frenchsquared.com
";
if ($_POST['comments'] != "") {
$message .= "
{$_POST['fname']} had the following comments:
{$_POST['comments']}
";
}
$headers = "";
$headers .= "From: " . $_POST['fname'] . " <" . $_POST['email'] . ">
";
$headers .= "Reply-To: " . $_POST['fname'] . " <" . $_POST['email'] . ">
";
$headers .= "X-Mailer: PHP4
" ; // mailer
$headers .= "X-Priority: 3
" ; // priority
$headers .= "Return-Path: $to
";
$headers .= "Origin: ".$_SERVER['REMOTE_ADDR']."
";
$headers .= "Content-Type: text/plain; charset=us-ascii
";
if (mail($to,$subject,$message,$headers)) {
echo "&reply=success";
} else {
echo "&reply=error";
}
?>
As you can see the website will be waiting for response but nothign happends :/. Can someone fix it or possibly give me a working email form.
Thanks