ASP: Sending a HTML form to an email address

Discussion in 'C#' started by cancer10, Feb 8, 2007.

  1. #1
    Hi,

    I am using CDONTs for sending email using ASP. I need to send a HTML form that takes values from a MS SQL Server database. How do I send this big code of form using ASP?

    I am using the following code to send the email


    <%
    Set myMail=CreateObject("CDO.Message")
    myMail.Subject="Sending email with CDO"
    myMail.From="mymail@mydomain.com"
    myMail.To="someone@somedomain.com"
    myMail.HTMLBody = "--FORM CODE HERE--" 
    myMail.Send
    set myMail=nothing
    %>
    Code (markup):


    The code for the form is as below

    
    <form method="post" target="_blank" action="http://tulleeho.com/tastemaker/members-feedback.asp">
      <table width="70%" border="0" align="center" cellpadding="3" cellspacing="4" style="border:1px dotted #CCCCCC;">
        <tr>
          <td class="style1"><div align="right"><span class="style1">Name:</span></div></td>
          <td><input type="text" name="txtuserFirstName" value="<% =rs("userFirstName") %>"></td>
        </tr>
        <tr class="style1">
          <td colspan="2"><HR align="right" style="border:1px dotted #CCCCCC;"></td>
        </tr>
        <tr>
          <td class="style1"><div align="right">Age:</div></td>
          <td><input type="text" name="txtUserAge" value="<%= datediff("yyyy",year(date),rs("userdateofBirth")) %>"></td>
        </tr>
        <tr class="style1">
          <td colspan="2"><HR align="right" style="border:1px dotted #CCCCCC;"></td>
        </tr>
        <tr>
          <td class="style1"><div align="right">Sex:</div></td>
          <td><select name="txtuserSex">
            <option value="<% if rs("usersex") = "True" then 	response.Write "1"
    	if rs("usersex") = "False" then	response.Write "0"%>"><% if rs("usersex") = "True" then 	response.Write "Male"
    	if rs("usersex") = "False" then	response.Write "Female"%></option>
            <option value="<% if rs("usersex") = "True" then response.Write "0"
    		if rs("usersex") = "False" then	response.Write "1"%>"><% if rs("usersex") = "True" then 	response.Write "Female"
    	if rs("usersex") = "False" then	response.Write "Male"%></option>
          </select>    </td>
        </tr>
        <tr class="style1">
          <td colspan="2"><HR align="right" style="border:1px dotted #CCCCCC;"></td>
        </tr>
        <tr>
          <td class="style1"><div align="right">City:</div></td>
          <td><select name="txtUserCity">
            <option <% if rs("userCity") = "Bangalore" then response.Write "selected" %>>Bangalore</option>
            <option <% if rs("userCity") = "New Delhi" then response.Write "selected" %>>New Delhi</option>
            <option <% if rs("userCity") = "Mumbai" then response.Write "selected" %>>Mumbai</option>
            <option <% if rs("userCity") = "Hyderabad" then response.Write "selected" %>>Hyderabad</option>
            <option <% if rs("userCity") = "Pune" then response.Write "selected" %>>Pune</option>
            <option <% if rs("userCity") = "Jaipur" then response.Write "selected" %>>Jaipur</option>
          </select>    </td>
        </tr>
        <tr class="style1">
          <td colspan="2"><HR align="right" style="border:1px dotted #CCCCCC;"></td>
        </tr>
        <tr>
          <td class="style1"><div align="right">Mobile No.: </div></td>
          <td><input type="text" name="txtuserPhoneNumberM" value="<% =rs("userPhoneNumberM") %>"></td>
        </tr>
        <tr class="style1">
          <td colspan="2"><HR align="right" style="border:1px dotted #CCCCCC;"></td>
        </tr>
        <tr>
          <td class="style1"><div align="right">Occupation:</div></td>
          <td><input type="text" name="txtuserOccupation"></td>
        </tr>
        <tr class="style1">
          <td colspan="2"><HR align="right" style="border:1px dotted #CCCCCC;"></td>
        </tr>
        <tr>
          <td valign="top" class="style1"><div align="right">Favourite Beverages:</div></td>
          <td valign="top" class="style1">
            Vodka: 
            <input type="checkbox" name="chkfav_bev" value="Vodka">
            Baileys:  <input type="checkbox" name="chkfav_bev" value="Baileys">
            
            Liqueur:  
            <input type="checkbox" name="chkfav_bev" value="Liqueur">
            <br>
            Tequila:  <input type="checkbox" name="chkfav_bev" value="Tequila">
            
            Whisky:  
            <input type="checkbox" name="chkfav_bev" value="Whisky">
            Peach Schnapps:  <input type="checkbox" name="chkfav_bev" value="Peach Schnapps">
            <br>
            Beer:  
            <input type="checkbox" name="chkfav_bev" value="Beer">
            Dark Rum:  <input type="checkbox" name="chkfav_bev" value="Dark Rum">
            
            White Rum:   
            <input type="checkbox" name="chkfav_bev" value="White Rum">
            Wine:  <input type="checkbox" name="chkfav_bev" value="Wine">
            Gin:  <input type="checkbox" name="chkfav_bev" value="Gin">      </td>
        </tr>
        <tr class="style1">
          <td colspan="2"><HR align="right" style="border:1px dotted #CCCCCC;"></td>
        </tr>
        <tr>
          <td valign="top" class="style1"><div align="right">****tails you drink:</div></td>
          <td><input type="text" name="txtuser****tails">
            <br>
            <input type="text" name="txtuser****tails">
            <br>
            <input type="text" name="txtuser****tails">
            <br>
          <input type="text" name="txtuser****tails"></td>
        </tr>
        <tr class="style1">
          <td colspan="2"><HR align="right" style="border:1px dotted #CCCCCC;"></td>
        </tr>
        <tr>
          <td valign="top" class="style1"><div align="right">Brands you purchase:</div></td>
          <td><p>
            <input type="text" name="txtuserBrands">
              <br>
            <input type="text" name="txtuserBrands">
            <br>
            <input type="text" name="txtuserBrands">
            <br>
            <input type="text" name="txtuserBrands">
            </p>
          <p>&nbsp; </p></td>
        </tr>
        <tr class="style1">
          <td colspan="2"><HR align="right" style="border:1px dotted #CCCCCC;"></td>
        </tr>
        <tr>
          <td class="style1"><div align="right">Favourite bar:</div></td>
          <td><input type="text" name="txtuserFavBar"></td>
        </tr>
        <tr class="style1">
          <td colspan="2"><HR align="right" style="border:1px dotted #CCCCCC;"></td>
        </tr>
        <tr>
          <td class="style1"><div align="right">Monthly spend on alcoholic beverages:</div></td>
          <td><select name="txtuserMonthlySpend">
            <option>0-500</option>
            <option>501-1000</option>
            <option>1001-1500</option>
            <option>More then 1500</option>
          </select>    </td>
        </tr>
        <tr class="style1">
          <td colspan="2"><HR align="right" style="border:1px dotted #CCCCCC;"></td>
        </tr>
        <tr>
          <td class="style1"><div align="right"></div></td>
          <td><input name="subfeedback" type="submit" id="subfeedback" value="Submit"></td>
        </tr>
      </table>
      <input name="txtuserid" type="hidden" value="<%=rs("userid") %>">
    </form>
    Code (markup):
     
    cancer10, Feb 8, 2007 IP
  2. TasteOfPower

    TasteOfPower Peon

    Messages:
    572
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    uh grab it from db, store it in variables, then set the form values to your variable values.
     
    TasteOfPower, Feb 9, 2007 IP
  3. lovehuahua

    lovehuahua Peon

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    <%
    Set myMail=CreateObject("CDO.Message")
    myMail.Subject="Sending email with CDO"
    myMail.From="mymail@mydomain.com"
    myMail.To="someone@somedomain.com"
    myMail.HTMLBody = "--FORM CODE HERE--"
    myMail.Send
    set myMail=nothing
    %>

    i think it will be failed to sent a email with those code.
    most of the eamil server need ur password and smtp address,verify!!
    so it is impassability to sent a email with asp module!!
    so ud better install the third service module for asp sending emails.
    JMail is good for asp.

    when u instal this module
    u can send mails by those code
    <%
    function sendbyjmail(toemail,tomailcc,tomailbcc,attachment,urlattachment,fromemail,fromname,loginname,password,titles,emailbody,stmpname,priority)
    priority=cint(priority)
    Set jmail = Server.CreateObject("JMAIL.Message")
    jmail.silent = true
    jmail.logging = true
    jmail.Charset = "GB2312"
    jmail.AddRecipient toemail '邮件收件人的地址
    if tomailcc<>"" then
    jmail.AddRecipientCC tomailcc '抄送
    end if
    if tomailbcc<>"" then
    jmail.AddRecipientBCC tomailbcc '暗送
    end if
    if attachment<>"" then
    jmail.AddAttachment server.MapPath(attachment) '附件
    end if
    if urlattachment<>"" then
    jmail.AddURLAttachment urlattachment '网络附件
    end if
    jmail.Priority = priority
    jmail.From = fromemail '发件人的E-MAIL地址,注意:部分服务器需要把邮件地址写全,如abc@zccn.net
    jmail.FromName = fromname
    jmail.MailServerUserName = loginname '登录邮件服务器所需的用户名
    jmail.MailServerPassword = password '登录邮件服务器所需的密码
    jmail.Subject = titles '邮件的标题
    if mailformat="html" then
    jmail.HTMLBody=emailbody
    else
    jmail.Body = emailbody '邮件的内容
    end if
    jmail.Send(stmpname) '执行邮件发送(通过邮件服务器地址)smtp.域名.com 不一定是邮件服务器
    jmail.Close()
    set jmail = nothing
    sendbyjmail=1
    end function
    %>

    i am bad in english.:)
    ^_^
     
    lovehuahua, Feb 10, 2007 IP
  4. cscsf

    cscsf Peon

    Messages:
    10
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I think you can use jmail
     
    cscsf, Feb 16, 2007 IP
  5. DaDMan

    DaDMan Guest

    Messages:
    566
    Likes Received:
    25
    Best Answers:
    0
    Trophy Points:
    0
    #5
    tasteofpower's right with you filled a var and use this var in .htmlbody
    or

    you could also output the form to a physical tmp html file on your server and then use the .CreateHTMLBody "your_temp_output.html" instead of .htmlbody in other words you passed a file ( containing the html output off course ) instead of a variable containing the same output...
     
    DaDMan, Feb 22, 2007 IP