开发者

Flash AS3 navigateToURL() and php mail()

开发者 https://www.devze.com 2023-03-29 06:23 出处:网络
I\'m trying to create a simple message form using navigateToURL() and PHP mail(). But 开发者_StackOverflow中文版I have a problem with this approach it redirects in the php page. I need it not to redir

I'm trying to create a simple message form using navigateToURL() and PHP mail(). But 开发者_StackOverflow中文版I have a problem with this approach it redirects in the php page. I need it not to redirect the page but still send it to the email.

here's what I did.

AS3

if (e.type == "click")
    {

                navigateToURL(new URLRequest("http://somedomain.com/sendme.php?" + "name=" + e.currentTarget.parent.na_txt.text + "&email=" + e.currentTarget.parent.ma_txt.text + "&contact=" + e.currentTarget.parent.co_txt.text + "&message=" + e.currentTarget.parent.me_txt.text + "&sex=" + e.currentTarget.parent.sex), "_self");


    }

PHP

<?php

$to = "some@email.com";
$subject = "Subject";

$name = $_GET['name']; 
$sex = $_GET['sex'];
$email = $_GET['email']; 
$contact = $_GET['contact']; 
$message = $_GET['message']; 

// create email headers
$headers = 'From: '.$email."\r\n".
'Reply-To: '.email."\r\n" .
'X-Mailer: PHP/' . phpversion();


$body = "From: $name \r\nGender: $sex \r\nE-Mail: $email \r\nContact No.: $contact \r\n\r\nMessage:\n$message";


echo "Thank You $name, Your Feedback and Enquiry has been submitted to <a href='mailto:$to'>$to</a>!";

mail($to, $subject, $body, $headers);


?> 


I think what you really want is to create a URLLoader object to send your variables though.

// prepare the vars
var vars:URLVariables = new URLVariables();
vars.name = e.currentTarget.parent.na_txt.text;
vars.email = e.currentTarget.parent.ma_txt.text;
vars.contact = e.currentTarget.parent.co_txt.text;
vars.message = e.currentTarget.parent.me_txt.text;
vars.sex = e.currentTarget.parent.sex;

// prepare the request
var request:URLRequest = new URLRequest("http://pennfolio.com/goahead/sendme.php");
request.data = vars;
request.method = URLRequestMethod.GET;

// prepare loader
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE,onLoadComplete);
loader.load(request);

// handle the response from PHP
function onLoadComplete(evt:Event):void
{
    evt.target.removeEventListener(Event.COMPLETE,onLoadComplete);
    trace(evt.target.data); // the output from PHP
}

This will run without reloading the page or opening a new window, allowing you to maintain the state of your application. The text that you echo from PHP will be available in the load complete handler function for you to display to the user however you choose.

0

精彩评论

暂无评论...
验证码 换一张
取 消