Yes another email form thread.
I’ve done some searching around on here and pieced together some knowledge and code from other people and came up with the following.
(I’m in a As 3.0 class right now, but teacher doesn’t teach how to code he just reads stuff so my AS skills is not that good )
It keeps giving me the error message of error sending in my dynamic text box that displays … well if it has been sent correctly or not.
I’ve got 4 fields …
- name_txt (user’s name)
- email (user’s email)
- findSite (how they found my site)
- message_txt (their message)
Then submit_btn as my sending button.
Sample is uploaded here …
removed because ppl can’t stop sending me blank e-mails
Anyways here is my AS 3.0 code …
//Import Classes
import flash.net.URLLoader
import flash.net.URLRequest
import flash.text.TextField;
import flash.text.TextFormat;
//Formatting text fields
name_txt.borderColor=0x000000;
name_txt.border=true;
name_txt.backgroundColor=0xFFFFFF;
name_txt.background=true;
//
email_txt.borderColor=0x000000;
email_txt.border=true;
email_txt.backgroundColor=0xFFFFFF;
email_txt.background=true;
//
findSite_txt.borderColor=0x000000;
findSite_txt.border=true;
findSite_txt.backgroundColor=0xFFFFFF;
findSite_txt.background=true;
//
message_txt.borderColor=0x000000;
message_txt.border=true;
message_txt.backgroundColor=0xFFFFFF;
message_txt.background=true;
////////////////////////////
submit_btn.addEventListener( MouseEvent.CLICK, submitClick );
// Send the form
function submitClick( e:MouseEvent ):void {
sendData();
}
//Passing Variables
function sendData():void {
var variables:URLVariables = new URLVariables();
variables.nameBox = name_txt.text;
variables.emailBox = email_txt.text;
variables.findSiteBox = findSite_txt.text;
variables.messageBox = message_txt.text;
variables.sendresponse = "SENDING"
status_txt.text = variables.sendresponse;
var _request:URLRequest = new URLRequest("contact.php");
_request.data = variables;
_request.method = URLRequestMethod.POST;
var loader:URLLoader = new URLLoader();
loader.dataFormat = URLLoaderDataFormat.VARIABLES;
loader.addEventListener( Event.COMPLETE, sendComplete );
loader.addEventListener( IOErrorEvent.IO_ERROR, sendIOError );
loader.load( _request );
}
//Form sent successfully
function sendComplete( e:Event ):void {
status_txt.text = "E-mail Sent";
clearForm();
var tmr:Timer = new Timer( 5000, 1 );
tmr.addEventListener( TimerEvent.TIMER, clearMessage );
tmr.start();
}
//Error in sending form
function sendIOError( e:IOErrorEvent ):void {
status_txt.text = "Error sending e-mail";
var tmr:Timer = new Timer( 5000, 1 );
tmr.addEventListener( TimerEvent.TIMER, clearMessage );
tmr.start();
}
//Clear form
function clearForm( ):void {
name_txt.text = "";
email_txt.text = "";
findSite_txt.text = "";
message_txt.text = "";
}
//Clear status message
function clearMessage( e:Event ):void {
status_txt.text = "";
}
Here is my contact.php code.
<?php
/* Pull POST data from Flash */
$nameBox=$_POST['nameBox'];
$emailBox=$_POST['emailBox'];
$findSiteBox=$_POST['findSiteBox'];
$messageBox=$_POST['messageBox'];
/* Title of the E-mail */
$subject = 'Ryan O. Hicks - Portfolio Site';
/* E-mail to send to*/
$toaddress='email removed for security reasons';
/*Defining the body for formatting purposes*/
$body = "From: $nameBox
E-Mail: $emailBox
How did you find the site: $findSiteBox
Message: $messageBox";
(mail($toaddress,$subject,$body))
/////////////////////////////////////////
/*Can't get to work so forget this code*/
/////////////////////////////////////////
/* Error check all data being sent from Flash. Simple formatting*/
//$nameBox=trim($nameBox);
//$emailBox=trim($emailBox);
//$subject=stripslashes($subject);
//$findSiteBox=stripslashes($findSiteBox);
//$messageBox=stripslashes($messageBox);
/* Send our e-mail
If mail() succeeds, respond with success message
If mail() fails, send with failure message
*/
//if
//{
//echo 'response=passed';
//} else {
//echo 'response=failed';
//}
/////////////////////////////////////////
?>