根据选择框选择发送电子邮件

时间:2013-05-01 13:39:42

标签: email drop-down-menu coldfusion coldfusion-7

我正在尝试使用旧版/旧版ColdFusion MX7提交表单结果,并且不运行PHP。我只为一封电子邮件工作。但是,我实际上需要根据用户从下拉菜单中选择的内容发送到不同的电子邮件。我只是不知道使用什么代码将完成的基于HTML的表单发送到正确的电子邮件。

代码:     

<cfif isdefined("FORM.send") and FORM.send eq "Send">  
    <cfmail from="ContactForm" to="contact@simpleform.com" 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>

1 个答案:

答案 0 :(得分:4)

马特说的......基本上是这样的:

<cfif structKeyExists(FORM, "send") and FORM.send eq "Send">  
    <cfswitch expression="#Form.team#">
        <cfcase value="teama">
            <cfset emailTo = "joe.bloggs@example.com">
        </cfcase>
        <cfcase value="teamb">
            <cfset emailTo = "teamB.email@example.com">
        </cfcase>
        ... etc
        <cfdefaultcase> <!--- default if all else fails --->
            <cfset emailTo = "contact@simpleform.com">
        </cfdefaultcase>
    </cfswitch>

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

另请注意使用structKeyExists而不是isDefined - 通常被认为是更好的做法。