2011-08-20 61 views
0

我想創建一個簡單的消息表單使用navigateToURL()和PHP郵件()。但是我在php頁面中重定向這種方法時遇到了問題。我需要它不要重定向頁面,但仍然發送到電子郵件。Flash AS3 navigateToURL()和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); 


?> 

回答

3

我想你真正想要的是創建一個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回顯的文本將在加載完成處理函數中提供,供您向用戶顯示,但是您可以選擇。

+0

感謝您的幫助..是的,它解決了我的問題。謝啦! – Pennf0lio