Es geht soweit das mailen von dem Server aus. Leider wird das erfolgreiche senden nich an das Flash zurück gesendet. Der Status "Sending..." bleibt in der Flash stehen.
Meine Frage habe ich im Syntax nen schnitzer?
Die ActionScript sieht so aus:
Ich weiss nicht mit php sicht so bescheid.
Bestes
Maxi
Meine Frage habe ich im Syntax nen schnitzer?
PHP-Code:
<?php
$yourName = $_POST['name']; // the variable needsto matchyour Actionscript
$fromEmail = $_POST['from']; // the variable needs to match yourActionscript
$yourSubject = $_POST['subject']; // the variable needs to matchyour Actionscript
$YourMsg = $_POST['msg']; // the variable needs to match yourActionscript
if( $yourName == true ) {
$sender = $fromEmail;
$yourEmail ="max@drauf.tv"; // This will beyour email address so please change this
$ipAddress = $_SERVER['REMOTE_ADDR']; // This gets the user's ipAddress
$emailMsg = "Name: $yourName sent this from IP:$ipAddress\n\nReturn Email: $sender\n\nSubject:$yourSubject\n\nMessage:\n\n$YourMsg \n\n Thisemail wassent usinga form on your site";
$return = "From: $sender\r\n" ."Reply-To:$sender \r\n" ."X-Mailer: PHP/" . phpversion();
if( mail( $yourEmail, $yourSubject, $emailMsg, $return))
{
echo "sentStatus=yes"; }
else { echo "sentStatus=no"; }
}
?>
PHP-Code:
/*************************************
Buttons
**************************************/
sendbtn.buttonMode = true;
sendbtn.addEventListener(MouseEvent.CLICK, submit);
resetbtn.buttonMode = true;
resetbtn.addEventListener(MouseEvent.CLICK, reset);
init();
/*************************************
Variables needed
**************************************/
var timer:Timer; var varLoad:URLLoader = new URLLoader;
var urlRequest:URLRequest = new URLRequest( "http://drauf.tv/sf/mail.php" );
urlRequest.method = URLRequestMethod.POST;
/*************************************
Functions
**************************************/
function init():void{
//Set all fields to empty
yourName.text = "";
fromEmail.text = "";
yourSubject.text = "";
YourMsg.text = "";
}
function submit(e:MouseEvent):void{
//Check to see if any of the fields are empty
if ( yourName.text == "" || fromEmail.text == "" || yourSubject.text == "" || YourMsg.text == "" ) {
valid.text = " All fields need to be filled.";
}
//Check if you're using a valid email address
else if( !checkEmail(fromEmail.text) ) {
valid.text = "Enter a valid email address";
}
else { valid.text = "Sending over the internet...";
var emailData:String = "name=" + yourName.text + "&from=" + fromEmail.text + "&subject=" + yourSubject.text + "&msg=" + YourMsg.text;
var urlVars:URLVariables = new URLVariables(emailData);
urlVars.dataFormat = URLLoaderDataFormat.TEXT;
urlRequest.data = urlVars; varLoad.load( urlRequest );
varLoad.addEventListener(Event.COMPLETE, thankYou );
}
}
function reset(e:MouseEvent):void{
init(); //call the initial clear function
}
function checkEmail(s:String):Boolean {
//This tests for correct email address
var p:RegExp = /(\w|[_.\-])+@((\w|-)+\.)+\w{2,4}+/;
var r:Object = p.exec(s);
if( r == null ) {
return false;
}
return true;
}
function thankYou(e:Event):void {
var loader:URLLoader =URLLoader(e.target);
var sent = new URLVariables(loader.data).sentStatus;
if( sent == "yes" )
{
valid.text = "Thanks for your email!"; timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, msgSent);
timer.start();
}
else {
valid.text = "Oh no! Something is wrong! Try again...";
}
}
function msgSent(te:TimerEvent):void {
if( timer.currentCount >= 10 ) { init();
timer.removeEventListener(TimerEvent.TIMER, msgSent);
}
}
Bestes
Maxi
Kommentar