2016-02-09 43 views
2

尝试从联系我们静态页面发送<cfmail>。它将只有一个收件人,我不想将其保存在后端。从静态页面发送cf邮件到单个收件人

<cfcase value="contact"> 
     <cfset caller.mainTitle = "Contact Us"> 

     <div id="contact_form"> 
      <cfform method="post" action="contact2" id="usrform"> 
       First Name<br> 
       <input class="textbox" type="text" name="firstName" value="First Name" onfocus="if (this.value=='First Name') this.value='';"> 
        <br> 
       Last Name<br> 
       <input class="textbox" type="text" name="lastName" value="Last Name" onfocus="if(this.value=='Last Name') this.value ='';"> 
        <br> 
       Email<br> 
       <input class="textbox" type="text" name="email" value="Email" onfocus="if(this.value=='Email') this.value='';"> 
        <br> 
       Phone Number<br> 
       <input class="textbox" type="text" name="phone" value="Phone Number" onfocus="if(this.value =='Phone Number') this.value='';"> 
        <br> 

       <input type="submit" class='submitBtn'> 
      </cfform> 
      <br> 
     </div> 
     <div class="commentsTop"> 
      <p style="color:black; font-size:18px; text-align:left;">We would love to hear from you!<p><br> 
      <textarea class="comments" rows="10" cols="100" name="comment" form="usrform" onfocus="if(this.value=='Enter your message here...') this.value='';">Enter your message here...</textarea> 
     </div> 


    </cfcase> 
    <cfcase value="contact2"> 

     <cfmail to="[email protected]" from="[email protected]" Subject="Message From Contact Us" type="HTML"> 


</cfmail> 

</cfcase> 

我有一个表格,我想附加为电子邮件的正文。不知道是否需要将表格作为<cfform>或者如果没有关系。

+4

什么问题? –

回答

1

这里是我会做什么:

我会用普通的HTML表单(CFFORM也未尝不可) 给行动形成(也可以是同一个页面,也可以有不同的提交页面。)

在提交页面,我会写的逻辑来发送邮件。(如果它的简单的邮件发送,没有什么复杂的正在发生的事情,然后CFM页面被罚款,否则CFC是首选)

Contactus.cfm

<form method="post" action="submitform.cfm" id="usrform"> 
    First Name<br> 
    <input class="textbox" type="text" name="firstName" value="First Name" onfocus="if (this.value=='First Name') this.value='';"> 
    <br> 
    Last Name<br> 
    <input class="textbox" type="text" name="lastName" value="Last Name" onfocus="if(this.value=='Last Name') this.value ='';"> 
    <br> 
    Email<br> 
    <input class="textbox" type="text" name="email" value="Email" onfocus="if(this.value=='Email') this.value='';"> 
    <br> 
    Phone Number<br> 
    <input class="textbox" type="text" name="phone" value="Phone Number" onfocus="if(this.value =='Phone Number') this.value='';"> 
    <br> 
    <input type="submit" class='submitBtn'> 
</form> 

Submitform.cfm

确保您传递正确的凭据和服务器的详细信息在CFMAIL

<cfmail to="[email protected]" from="[email protected]" Subject="Message From Contact Us" type="HTML"> 

<!--- Your message body (you can use your form variable here) ---> 
FistName: #form.firstName# 
LastName: #form.lastName# 

</cfmail> 
+0

非常感谢。我试图通过一次通话发送整个表单,但这样做会很好。 – arandrup5865

+3

你欠OP一杯啤酒。他接受你的答案给了你4位数的声望。 –

+0

我希望OP有时会给我啤酒。 – TRose

0

一个文件解决方案,

<form method="post" action="?"> 
    First Name<br> 
    <input class="textbox" type="text" name="firstName" value="First Name" onfocus="if (this.value=='First Name') this.value='';"> 
    <br> 
    Last Name<br> 
    <input class="textbox" type="text" name="lastName" value="Last Name" onfocus="if(this.value=='Last Name') this.value ='';"> 
    <br> 
    Email<br> 
    <input class="textbox" type="text" name="email" value="Email" onfocus="if(this.value=='Email') this.value='';"> 
    <br> 
    Phone Number<br> 
    <input class="textbox" type="text" name="phone" value="Phone Number" onfocus="if(this.value =='Phone Number') this.value='';"> 
    <br> 


    <p style="color:black; font-size:18px; text-align:left;">We would love to hear from you!<p><br> 
     <textarea class="comments" rows="10" cols="100" name="comment" onfocus="if(this.value=='Enter your message here...') this.value='';">Enter your message here...</textarea> 

    <input type="submit" class='submitBtn'> 
</form> 


<cfif cgi.request_method EQ "post"> 

    <cfmail to="[email protected]" from="[email protected]" Subject="Message From Contact Us" type="HTML"> 

    <!--- Your message body (you can use your form variable here) ---> 
    <cfloop index="i" list="#Form.FieldNames#" delimiters=","> 
     #i# = #Form[i]#<br> 
    </cfloop> 
</cfmail> 

</cfif> 

注:备注字段不是内部表格

另请参阅:

Display CFLoop Items in Order from Form

相关问题