2013-10-02 78 views
0

我有一個橫幅廣告的用戶可以填寫自己的信息(姓名,電子郵箱,電話號碼),他們可以選擇從「組合框」列表中的商店發送電子郵件。提交表格後,信息會發送到一個特定的電子郵件地址。我想要做的是根據從店鋪列表中選擇的值發送信息。根據所選值

例如,如果用戶選擇商店A電子郵件進入收件人甲,並且如果選擇店乙的信息將被髮送到接收者B

我將如何實現這一目標?

/*ActionScript 3.0 */ 

// custom function we create to populate the comboBox list 
function addShopsToList():void { 
shopList.addItem({ label: "Shop A" });  
shopList.addItem({ label: "Shop B" });  
} 
// Run function above now 
addShopsToList(); 

// build variable name for the URL Variables loader 
var variables:URLVariables = new URLVariables; 

// Build the varSend variable 
var varSend:URLRequest = new URLRequest("form_parse_rus.php"); 
varSend.method = URLRequestMethod.POST; 
varSend.data = variables; 

// Build the varLoader variable 
var varLoader:URLLoader = new URLLoader; 
varLoader.dataFormat = URLLoaderDataFormat.VARIABLES; 
varLoader.addEventListener(Event.COMPLETE, completeHandler); 

// handler for the PHP script completion and return of status 
function completeHandler(event:Event):void { 
// remove processing clip 
name_txt.text = ""; 
email_txt.text = ""; 
phone_txt.text = ""; 

// Load the response from php here 
status_txt.text = event.target.data.return_msg; 
    } 

// Add event listener for submit button click 
submit_btn.addEventListener(MouseEvent.CLICK, ValidateAndSend); 

// function ValidateAndSend 
function ValidateAndSend (event:MouseEvent):void { 

// validate fields 
if(!name_txt.length) { 
    status_txt.text = "Please enter your name"; 
} else if (!email_txt.length) { 
    status_txt.text = "Pleaser enter your e-mail"; 
} else if (!phone_txt.length) { 
    status_txt.text = "Please enter your phone number"; 
} else { 

    // All is good, send the data now to PHP 

    // ready the variables in our form for sending 
    variables.userName = name_txt.text; 
    variables.userEmail = email_txt.text;  
    variables.userPhone = phone_txt.text; 
    variables.userShop = shopList.value; 

    // Send the data to PHP now 
    varLoader.load(varSend); 

} // close else condition for error handling 

} // close validate and send function 

PHP腳本負責發送電子郵件:

編輯:

<?php 

// Create local variables from the Flash ActionScript posted variables 
$senderName = $_POST['userName']; 
$senderEmail  = $_POST['userEmail']; 
$senderPhone = $_POST['userPhone']; 

if(isset($_POST['userShop']) == "Shop A"){ 
$senderShop = "[email protected]"; 
} 
elseif($_POST['userShop'] == "Shop B"){ 
    $senderShop = "[email protected]"; 
} 


// Strip slashes on the Local typed-in variables for security and run any php based error check here 
$senderName = stripslashes($senderName); 
$senderEmail  = stripslashes($senderEmail); 
$senderMessage = stripslashes($senderMessage); 

$to = "$senderShop";    
$from = "$senderEmail"; 
$subject = "Mushroom vs Master"; 
$message = "Mushroom vs Master: 

Nimi: $senderName 
Email: $senderEmail 
Telefon: $senderPhone 
Esindus: $userShop"; 


// $headers Variables 
$headers = "From: $from\r\n"; 
$headers .= "Content-type: text\r\n"; 
$to = "$to"; 
    // Send the email 
    mail($senderShop, $subject, $message, $headers); 


    // The flash ActionScript is looking for a return variable of "return_msg" 
    $my_msg = "Thank you $senderName, for submitting."; 
    // Print the data back to flash who is patiently waiting for it in the onCompleteHandler 
    print "return_msg=$my_msg"; 
// Exit script 
exit(); 
?> 

回答

0
if(isset($_POST['userShop']) == "shop A"){ 
    $senderShop = "[email protected]"; 
    } 
    elseif($_POST['userShop'] == "shop B"){ 
     $senderShop = "[email protected]"; 
    } 
    .....and so on 

您的郵件功能將是:

mail($senderShop, $subject, $message, $headers); 
+0

我認爲$ senderShop就是店名,不是嗎?我想你會想要在代碼中設置$值來更改郵件發送的位置。 – danielpsc

+0

跳過這一點,您的編輯命中,而我輸入我的評論! :) – danielpsc

+0

$ senderShop是店名,是的。目前信息仍然只發送到一個電子郵件地址。 – Laniakea