2016-02-09 44 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

相關問題