Flash AS3 navigatorToURL() 和 php mail()

发布于 2024-11-30 08:32:10 字数 1319 浏览 2 评论 0原文

我正在尝试使用navigateToURL() 和PHP mail() 创建一个简单的消息表单。但我对这种在 php 页面中重定向的方法有疑问。我需要它不重定向页面,但仍将其发送到电子邮件。

这就是我所做的。

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 = "[email protected]";
$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'm trying to create a simple message form using navigateToURL() and PHP mail(). But 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 = "[email protected]";
$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);


?> 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

满栀 2024-12-07 08:32:10

我认为您真正想要的是创建一个 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
}

这将在不重新加载页面或打开新窗口的情况下运行,从而允许您维护应用程序的状态。您从 PHP 回显的文本将在加载完成处理函数中可用,供您以您选择的方式向用户显示。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文