so i’m trying to make a Contact form that would be sent thorugh email from a web page… but something just doesn’t work… i think the code, both PHP and AS3 is correct but i wanna double check it out with you ppl… so here is the code:
PHP:
<?php
/*
--- Created By Adam @ www.developphp.com ---
--- For help or script expansion join our forums there ---
--- Use this code as your own any way you like ---
*/
// Create local PHP variables from the info the user gave in the Flash form
$senderName = $_POST['userName'];
$senderEmail = $_POST['userEmail'];
$senderMessage = $_POST['userMsg'];
// Strip slashes on the Local variables
$senderName = stripslashes($senderName);
$senderEmail = stripslashes($senderEmail);
$senderMessage = stripslashes($senderMessage);
//!!!!!!!!!!!!!!!!!!!!!!!!! change this to your email !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
$to = "dpcdpc11@gmail.com";
$from = "contact@mytestingsite.atwebpages.com";
$subject = $_POST["subject"];
//Begin HTML Email Message
$message = <<<EOF
<html>
<body bgcolor="#FFFFFF">
<b>Name</b> = $senderName<br /><br />
<b>Email</b> = <a href="mailto:$senderEmail">$senderEmail</a><br /><br />
<b>Message</b> = $senderMessage<br />
</body>
</html>
EOF;
//end of message
$headers = "From: $from
";
$headers .= "Content-type: text/html
";
$to = "$to";
mail($to, $subject, $message, $headers);
exit();
?>
AS3:
stop();
import flash.events.*;
import flash.net.URLLoader;
import flash.net.URLLoaderDataFormat;
import flash.net.URLRequest;
// ----------------------------------------------------------------
var variables:URLVariables = new URLVariables();
var varSend:URLRequest = new URLRequest("email.php");
var varLoader:URLLoader = new URLLoader;
varSend.method = URLRequestMethod.POST;
varSend.data = variables;
status_txt.text = "";
submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend);
function ValidateAndSend(event:MouseEvent):void{
//validate form fields
if(!name_txt.length) {
status_txt.text = "Please enter your name.";
} else if(!email_txt.length) {
status_txt.text = "Please enter an email address";
} else if(!validateEmail(email_txt.text)) {
status_txt.text = "Please enter a VALID email address";
} else if(!msg_txt.length) {
status_txt.text = "Please enter a message.";
} else {
status_txt.text = "Thanks " + name_txt.text + ", your message has been sent!";
variables.userName = name_txt.text;
variables.userEmail = email_txt.text;
variables.userMsg = msg_txt.text;
variables.subject = subject_txt.text;
varLoader.load(varSend);
gotoAndStop(2);
}
}
function validateEmail(str:String):Boolean {
var pattern:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
var result:Object = pattern.exec(str);
if(result == null) {
return false;
}
return true;
}
and here is the link to the contact form on the server: http://mytestingsite.atwebpages.com/
is the code correct or it might be the free server that i’m using??
hope some could really help me on this one!
thanks in advanced!!