Multiple fields using Mail.Body = Request("")?RSS

13 replies

Last post Apr 07, 2006 03:19 PM by tomkmvp

  • Multiple fields using Mail.Body = Request("")?

    Mar 24, 2006 02:17 AM|jetstar|LINK

    I am having problems with is getting information from multiple fields into the body of the e-mail.  I can get only get it to work with one form element:

    <%
       Set Mail = Server.CreateObject("Persits.MailSender")
       Mail.Host = "smtp.broadviewnet.net"
       Mail.From = "From Address"
       Mail.FromName = "From Name"
       Mail.AddAddress "email@recipient.net"
       Mail.Subject = "Enquiry"
       Mail.Body = Request("name")
    %>


    How would I change Mail.Body = Request("name") to also include info from other form elements such as "phone", "email" and "enquiry"?
  • Re: Multiple fields using Mail.Body = Request("")?

    Mar 24, 2006 01:35 PM|jeff@zina.com|LINK

    Concatenate the form responses into a single string.  Try:

    <%
       Set Mail = Server.CreateObject("Persits.MailSender")
       Mail.Host = "smtp.broadviewnet.net"
       Mail.From = "From Address"
       Mail.FromName = "From Name"
       Mail.AddAddress "email@recipient.net"
       Mail.Subject = "Enquiry"
       Mail.Body = "The name is: " & Request.Form("name") & VbCrLf
       Mail.Body = "The phone number is: " & Request.Form("phone") & VbCrLf
       Mail.Body = "The email is: " & Request.Form("email") & VbCrLf
    %>

    "&" concatenates a string, and the VbCrLf inserts a Carriage Return / Line Feed into the string so it will break to the next line in the email.  If you do HTML format, instead of VbCrLf use <br>.

    Jeff

    Have you Binged a solution before posting?
  • Re: Multiple fields using Mail.Body = Request("")?

    Mar 24, 2006 10:33 PM|jetstar|LINK

    Hi Jeff. Thanks for your help. When I used the code you posted the only result I get in the email is the content of the last form element, which is the enquiry multiline text field. I also tried the following but got the same result:

    Mail.Body = "Name: " & Request.Form("Name") & VbCrLf & Request.Form("Phone") & VbCrLf & Request.Form("Email") & VbCrLf & Request.Form("Contact Method") & VbCrLf & Request.Form("Enquiry") & VbCrLf

    Maybe you can get a clearer look at it if I post the whole page? Thanks for your help.

    <%

                ' change to address of your own SMTP server

                strHost = "mail.mysite.net"

     

                If Request("Send") <> "" Then

                           

                            Set Mail = Server.CreateObject("Persits.MailSender")

                            ' enter valid SMTP host

                            Mail.Host = strHost

     

                            Mail.From = "From Address" ' From address

                            'Mail.FromName = Request("From Name")

                            Mail.AddAddress "myself@myemail.com"

                           

                            ' message subject

                            Mail.Subject = " Enquiry"

                            ' message body

                            Mail.Body = "Name: " & Request.Form("Name") & VbCrLf

                            Mail.Body = "Phone: " & Request.Form("Phone") & VbCrLf

                            Mail.Body = "Email: " & Request.Form("Email") & VbCrLf

                            Mail.Body = "Preferred Contact: " & Request.Form("Contact Method") & VbCrLf

                            Mail.Body = "Enquiry: " & Request.Form("Enquiry") & VbCrLf

     

                            strErr = ""

                            bSuccess = False

                            On Error Resume Next ' catch errors

                            Mail.Send        ' send message

                            If Err <> 0 Then ' error occurred

                                        strErr = Err.Description

                            else

                                        bSuccess = True

                            End If

                End If

    %>

     

    <HTML>

    <HEAD>

    <TITLE>AspEmail: Simple.asp</TITLE>

    </HEAD>

    <BODY BGCOLOR="#FFFFFF">

     

    <H2>AspEmail: Simple.asp</h2>

     

    <% If strErr <> "" Then %>

    <h3><FONT COLOR="#FF0000">Error occurred: <I><% = strErr %></I></FONT></h3>

    <% End If %>

     

    <% If bSuccess Then %>

    <h3><FONT COLOR="#00A000">Thanks! Your enquiry has been received.</FONT></h3>

    <% End If %>

     

    <FORM METHOD="POST" ACTION="Simple.asp">

     

    <TABLE CELLSPACING=0 CELLPADDING=2 BGCOLOR="#E0E0E0">

                <TR>

                           

          <TD width="216">Host (change as necessary in script):</TD>

                           

          <TD width="187"><B>

            <% = strHost %>

            </B></TD>

                </TR>

                <TR>

                           

          <TD width="216">Name</TD>

                           

          <TD width="187">

            <input type="TEXT" name="Name">

          </TD>

                </TR>

                <TR>

                           

          <TD width="216">Email</TD>

                           

          <TD width="187">

            <input type="TEXT" name="Email">

          </TD>

                </TR>

                <TR>

                           

          <TD width="216">Phone</TD>

                           

          <TD width="187">

            <input type="TEXT" name="Phone">

          </TD>

                </TR>

                <TR>

                           

          <TD width="216">Preferred contact:</TD>

          <TD width="187">

            <table width="100%" border="0" cellspacing="0" cellpadding="0">

              <tr>

                <td width="12%">

                  <input type="radio" name="Contact Method" value="E-mail">

                </td>

                <td width="43%"><span class="bodytext">E-mail</span></td>

                <td width="4%">

                  <input type="radio" name="Contact Method" value="Phone">

                </td>

                <td width="41%"><span class="bodytext">Phone</span></td>

              </tr>

            </table>

          </TD>

                </TR>

                <TR>

                           

          <TD width="216">Enquiry:</TD>

          <TD width="187">

            <textarea name="Enquiry"></textarea>

          </TD>

                </TR>

                <TR>

                            <TD COLSPAN=2><INPUT TYPE="SUBMIT" NAME="Send" VALUE="Send Message"></TD>

                </TR>

     

    </TABLE>

     

    </FORM>

     

    </BODY>

    </HTML>

  • Re: Multiple fields using Mail.Body = Request("")?

    Mar 27, 2006 03:09 PM|jeff@zina.com|LINK

    Crap.  That's what I get for typing too fast and not proofing my code.  :)

    Should have done what I said to do, not what I coded:

    Mail.Body = "Name: " & Request.Form("Name") & VbCrLf
    Mail.Body = Mail.Body & "Phone: " & Request.Form("Phone") & VbCrLf
    Mail.Body = Mail.Body & "Email: " & Request.Form("Email") & VbCrLf
    Mail.Body = Mail.Body & "Preferred Contact: " & Request.Form("Contact Method") & VbCrLf
    Mail.Body = Mail.Body & "Enquiry: " & Request.Form("Enquiry") & VbCrLf

    That's concatentation, what I wrote originally just reset the Mail.Body variable on each line.  Each subsequent line after the first adds the new string onto the end of the existing Mail.Body string.  Sorry for not paying attention.

    Jeff

    Have you Binged a solution before posting?
  • Re: Multiple fields using Mail.Body = Request("")?

    Mar 28, 2006 06:56 AM|jetstar|LINK

    Thanks Jeff. You're a legend.
  • Re: Multiple fields using Mail.Body = Request("")?

    Apr 03, 2006 02:52 PM|evolved02|LINK

    Here is what I have, and it is not working

    set mail = server.CreateObject("CDONTS.NewMail")
    mail.From = Request("EmailAddress")
    mail.To = "propertysearch@aol.com"
    mail.Subject = "New Property Search"
    Mail.Body = "Full Name: " & Request.Form("FullName") & VbCRLf
    Mail.Body = Mail.Body & "Email Address: " & Request.Form("EmailAddress") & VbCRLF
    Mail.Body = Mail.Body & "Home Phone: " & Request.Form("HomePhone") & VbCRLF
    Mail.Body = Mail.Body & "Mobile Phone: " & Request.Form("MobilePhone") & VbCRLF
    Mail.Body = Mail.Body & "PriceRange: " & Request.Form("PriceRange") & VbCRLF
    Mail.Body = Mail.Body & "County: " & Request.Form("County") & VbCRLF
    Mail.Body = Mail.Body & "HomeStyle: " & Request.Form("HomeStyle") & VbCRLF
    Mail.Body = Mail.Body & "ZipCode: " & Request.Form("ZipCode") & VbCRLF
    Mail.Body = Mail.Body & "Comments: " & Request.Form("Comments") & VbCRLF
    mail.Send
    set mail = nothing

  • Re: Multiple fields using Mail.Body = Request("")?

    Apr 03, 2006 03:58 PM|jeff@zina.com|LINK

    Not working as in when you use this code your girlfriend unplugs your network connection?  The solution for that is to hot glue the cable to the socket.  Or hot glue the girlfriend to the chair.

    Jeff

    Have you Binged a solution before posting?
  • Re: Multiple fields using Mail.Body = Request("")?

    Apr 03, 2006 05:54 PM|tomkmvp|LINK

    Is there an error?  Nothing happens?  ... ?
  • Re: Multiple fields using Mail.Body = Request("")?

    Apr 04, 2006 05:32 PM|evolved02|LINK

    MAN....and all this time I've been searching google for an answer, my GF has been unplugging the cable.....ur amazing

    ahhhh...back to the problem

    I get the standard "page cannot be displayed" when it runs the asp script and it doesn't send the email...but If I remove Mail.Body &,  and send like this

    Mail.Body = "Full Name: " & Request.Form("FullName") & VbCRLf
    mail.Send
    set mail = nothing

    I get the email with the correct format, but I try and add multiple mail.body sequences and nothing

    weird 

     

     

  • Re: Multiple fields using Mail.Body = Request("")?

    Apr 05, 2006 08:44 AM|tomkmvp|LINK

    Make sure friendly error messages are turned off in IE.  There must be a more descriptive error message.
  • Re: Multiple fields using Mail.Body = Request("")?

    Apr 05, 2006 09:02 AM|jeff@zina.com|LINK

    Response.Write out the Mail.Body and comment out the mail.Send line to see what you're actually getting.  Also, is the mail not getting sent, is it stuck in the queue, etc.  Check the SMTP logs for that information.

    Jeff

    Have you Binged a solution before posting?
  • Re: Multiple fields using Mail.Body = Request("")?

    Apr 07, 2006 11:04 AM|evolved02|LINK

     This is the error i get.....

    Microsoft VBScript runtime error '800a01b6'

    Object doesn't support this property or method: 'mail.Body'

    /Contact.asp, line 8

  • Re: Multiple fields using Mail.Body = Request("")?

    Apr 07, 2006 01:58 PM|jeff@zina.com|LINK

    Check you case.  Post the full code.  And use CDO instead of CDONTS, it's been deprecated.

    Jeff

    Have you Binged a solution before posting?
  • Re: Multiple fields using Mail.Body = Request("")?

    Apr 07, 2006 03:19 PM|tomkmvp|LINK