根据所选值发送电子邮件

时间:2013-10-02 08:52:35

标签: php actionscript-3 email flash-cs6

我有一个横幅,用户可以在其中填写他们的信息(姓名,电子邮件,电话号码),他们可以从“ComboBox”列表中选择一个商店。提交表单后,信息将转到一个特定的电子邮件地址。我想做的是根据从商店列表中选择的值发送信息。

例如,如果用户选择商店A ,则电子邮件将转至收件人A ,如果选择商店B ,则信息将为被发送给收件人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   = "recipient_A_@mail.com";
}
elseif($_POST['userShop'] == "Shop B"){
     $senderShop   = "recipient_B_@mail.com";
}


// 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();
?>

1 个答案:

答案 0 :(得分:0)

if(isset($_POST['userShop'])  == "shop A" ){
    $senderShop   = "recipientA@abc.com";
    }
    elseif($_POST['userShop'] == "shop B"){
         $senderShop   = "recipientB@abc.com";
    }
     .....and so on

您的邮件功能将是:

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