2013-05-01 160 views
1

我試圖使用ColdFusion MX7的舊/舊版本提交表單結果,並且不運行PHP。我只用一封郵件工作。但是,實際上,我需要將其發送到不同的電子郵件,具體取決於某人從下拉菜單中選擇的內容。我只是不知道用什麼代碼將完成的基於HTML的表單發送到正確的電子郵件。根據選擇框選擇發送電子郵件

代碼:

<cfif isdefined("FORM.send") and FORM.send eq "Send"> 
    <cfmail from="ContactForm" to="[email protected]" subject="SimpleForm" type="html"> 
    Name: #FORM.TXTNAME# 
    Business Name: #FORM.TXTBUSINESSNAME# 
    Email: #FORM.TXTEMAIL# 
    Phone: #FORM.TXTPHONE# 
    Comment: #FORM.TXTCOMMENT# 
    Date/Time Sent: #dateformat(now(), "yyyy/mm/dd")# at #timeformat(now(), "HH:mm:ss tt")# 
    </cfmail> 
</cfif> 

<html xmlns="http://www.w3.org/1999/xhtml"> 
<head> 
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 
<title>Simple Contact Form</title> 
</head> 

<body> 
<fieldset> 
    <legend>Contact Form</legend> 
    <form id="simpleForm" name="simpleForm" method="post" action=""> 
    <table width="100%" border="0" cellspacing="0" cellpadding="4"> 
     <tr> 
      <td width="20%" align="right">Name:</td> 
      <td width="80%"><input type="text" name="txtName" id="txtName" /></td> 
     </tr> 
     <tr> 
      <td align="right">Business Name:</td> 
      <td><input type="text" name="txtBusinessName" id="txtBusinessName" /></td> 
     </tr> 
     <tr> 
      <td align="right">Email:</td> 
      <td><input type="text" name="txtEmail" id="txtEmail" /></td> 
     </tr> 
     <tr> 
      <td align="right">Phone:</td> 
      <td><input type="text" name="txtPhone" id="txtPhone" /></td> 
     </tr> 
     <tr> 
      <td align="right" valign="top">Comment:</td> 
      <td><textarea name="txtComment" id="txtComment" cols="45" rows="5"></textarea></td> 
     </tr> 
     <tr> 
      <td>&nbsp;</td> 
      <td><hr width="100%" size="1" /></td> 
     </tr> 
     <tr> 
      <td>&nbsp;</td> 
      <td><input type="submit" name="send" id="send" value="Send" /></td> 
     </tr> 
    </table> 


<SELECT SIZE="1" name="team"> 
<OPTION>Select your team</OPTION> 
<OPTION VALUE="teama" name="teama">Team A</OPTION> 
<OPTION VALUE="teamb" name="teamb">Team B</OPTION> 
<OPTION VALUE="teamc" name="teamc">Team C</OPTION> 
<option value="teamc" name="teamc">Team D</option> 
</SELECT> 
    </form> 
</fieldset> 
</body> 
</html> 
+0

一旦你的表單被提交,你可以訪問form.team來確定用戶選擇了什麼。那是你的追求? – 2013-05-01 14:04:39

+0

如果用戶選擇團隊A,則表單需要通過電子郵件發送給團隊主管。與團隊B-D一樣。我猜這個邏輯是這樣的: [insert表單結果] 2013-05-01 14:09:56

回答

4

馬特說什麼...基本上是這樣的:

<cfif structKeyExists(FORM, "send") and FORM.send eq "Send"> 
    <cfswitch expression="#Form.team#"> 
     <cfcase value="teama"> 
      <cfset emailTo = "[email protected]"> 
     </cfcase> 
     <cfcase value="teamb"> 
      <cfset emailTo = "[email protected]"> 
     </cfcase> 
     ... etc 
     <cfdefaultcase> <!--- default if all else fails ---> 
      <cfset emailTo = "[email protected]"> 
     </cfdefaultcase> 
    </cfswitch> 

    <cfmail from="ContactForm" to="#emailTo#" subject="SimpleForm" type="html"> 
    ... 
    </cfmail> 
</cfif> 

還要注意使用structKeyExists代替isDefined的 - 通常被認爲是更好的做法。

+0

我將代碼添加到了我已有的代碼中,但雖然沒有收到任何錯誤,但我也沒有收到任何電子郵件。 – 2013-05-01 15:36:41

+1

嘗試從「contactform」更改爲from =「[email protected]」coldfusion或者您的SMTP服務器可能將其移至無法投遞的文件夾。我總是用 steve 2013-05-01 15:41:45

+0

包裝我的郵件statemenets試過,但我實際上收到的電子郵件仍然是=「contactform」,而是=「我@電子郵件.COM」。 – 2013-05-01 15:58:52

相關問題