简体   繁体   English

Flash AS3 NavigationToURL()和php mail()

[英]Flash AS3 navigateToURL() and php mail()

I'm trying to create a simple message form using navigateToURL() and PHP mail(). 我正在尝试使用NavigationToURL()和PHP mail()创建一个简单的消息表单。 But I have a problem with this approach it redirects in the php page. 但我有这种方法的问题,它在php页面中重定向。 I need it not to redirect the page but still send it to the email. 我不需要重定向页面,但仍将其发送到电子邮件。

here's what I did. 这就是我所做的。

AS3 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

<?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. 我认为您真正想要的是创建一个URLLoader对象来发送变量。

// 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. 您从PHP回显的文本将在加载完成处理程序函数中提供,供您选择显示给用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM