SitePoint Sponsor

User Tag List

Results 1 to 20 of 20

Hybrid View

  1. #1
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have a form i.e. Name, Phone, Fax, etc. including a drop-down list of "client" names. When the form is submitted I need for the selected "client" to be e-mailed a copy of the form. How do I go about doing this? Javascript & ASP?

    Thanks

  2. #2
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, most likely, it would just be ASP (if that is indeed your language of choice). You would simply use the form elements as variables. That is to say, to make 'Name' a variable with the form information you would write:
    Code:
    <%dim varName
    varName = Request.Form("ElementName")
    %>
    Where 'ElementName' is the Name of the form element.

    Post here with all your field names, and whether you are still interested or not, and i'll whip up the e-mail script right here for you.

    Hope this helps!
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  3. #3
    SitePoint Wizard TWTCommish's Avatar
    Join Date
    Aug 1999
    Location
    Pittsburgh, PA, USA
    Posts
    3,910
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you like PHP (and who doesn't? ), you could try something like this:

    PHP Code:
    <?php
      
    if ($sendmail) {
      
    ?>
      <form action="<?php echo($PHP_SELF); ?>" method="post">
      Subject: <input type="text" name="subject"><br>
      Recipient: <select name="email">
      <option value="msimpson@email.com">Maggie Simpson</option>
      <option value="hsimpson@email.com">Homer Simpson</option>
      <option value="asimpson@email.com">Grandpa Simpson</option>
      </select><p>
      Message:<br>
      <textarea name="body" rows="6" cols="30" wrap><p>
      <input type="submit" name="sendmail" value="Send Email!"><br>
      <?php
      
    } else {
      
    $mail mail($email$subject$body);
        if (
    $mail) {
        echo(
    "Mail successfully sent to $email!");
        } else {
        echo(
    "An error has occurred.");
        }
      }
    Good luck!

    EDIT: This might be better off in one of the Server-Side scripting forums - JavaScript would likely only come into play if you wanted to validate the form's contents instantly.
    Last edited by TWTCommish; Feb 13, 2001 at 08:04.

  4. #4
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by goober
    Well, most likely, it would just be ASP (if that is indeed your language of choice). You would simply use the form elements as variables. That is to say, to make 'Name' a variable with the form information you would write:
    Code:
    <%dim varName
    varName = Request.Form("ElementName")
    %>
    Where 'ElementName' is the Name of the form element.

    Post here with all your field names, and whether you are still interested or not, and i'll whip up the e-mail script right here for you.

    Hope this helps!
    Form needs to be submitted to a specific person always, and a carbon copy to the selected "Supervisor".
    The "Traveler" does not need to be e-mailed.


    <HTML>
    <HEAD>
    <TITLE>Form</TITLE>
    </HEAD>
    <BODY vLink=#660066 aLink=#669900 link=#3333FF bgColor=#ffffff leftMargin=4 topMargin=0 marginheight="0"
    marginwidth="4" text="#000000">
    <FORM method=POST action="http://www.myserver.com/bin/mailto.exe">
    <INPUT type=HIDDEN name="sendto" value="info@mydomain.com">
    <INPUT type=HIDDEN name="server" value="mail.myserver.net">
    <INPUT type=HIDDEN name="SUBJECT" value="Form">
    <INPUT type=HIDDEN name="resulturl" value="thanks.htm">
    <TABLE WIDTH="58%" BORDER="0" MM_NOCONVERT="TRUE" ALIGN="CENTER">
    <TR BGCOLOR="#FFFFCC" VALIGN="middle">
    <TD WIDTH="29%" HEIGHT="76">&nbsp;</TD>
    <TD WIDTH="71%" HEIGHT="76">&nbsp;</TD>
    </TR>
    <TR BGCOLOR="#FFFFCC" VALIGN="middle">
    <TD WIDTH="29%">
    <DIV ALIGN="RIGHT"><FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="-1"><B>Traveler/B>
    </FONT></DIV>
    </TD>
    <TD WIDTH="71%">
    <SELECT NAME="Traveler">
    <OPTION VALUE="SELECT A NAME" SELECTED>SELECT A
    NAME</OPTION>
    <OPTION VALUE="Joe">Joe</OPTION>
    <OPTION VALUE="Jane">Jane</OPTION>
    <OPTION VALUE="Rob">Rob</OPTION>
    </SELECT>
    </TD>
    </TR>
    <TR BGCOLOR="#FFFFCC" VALIGN="middle">
    <TD WIDTH="29%" HEIGHT="12">&nbsp;</TD>
    <TD WIDTH="71%" HEIGHT="12">&nbsp;</TD>
    </TR>
    <TR BGCOLOR="#FFFFCC">
    <TD WIDTH="29%">
    <DIV ALIGN="RIGHT"><FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="-1">Your
    supervisor: </FONT></DIV>
    </TD>
    <TD WIDTH="71%">
    <SELECT NAME="Supervisor">
    <OPTION VALUE="SELECT A NAME" SELECTED>SELECT A
    NAME</OPTION>
    <OPTION VALUE="Don">Don</OPTION>
    <OPTION VALUE="Art">Art</OPTION>
    <OPTION VALUE="Bernie">Bernie</OPTION>
    </SELECT>
    </TD>
    </TR>
    <TR BGCOLOR="#FFFFCC">
    <TD WIDTH="29%">&nbsp;</TD>
    <TD WIDTH="71%">&nbsp;</TD>
    </TR>
    <TR BGCOLOR="#FFFFCC">
    <TD WIDTH="29%">&nbsp;</TD>
    <TD WIDTH="71%">&nbsp;</TD>
    </TR>
    <TR BGCOLOR="#FFFFCC">
    <TD WIDTH="29%">
    <DIV ALIGN="RIGHT"><FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="-1">division:
    </FONT></DIV>
    </TD>
    <TD WIDTH="71%">
    <INPUT TYPE="text" NAME="Division" SIZE="25">
    </TD>
    </TR>
    <TR BGCOLOR="#FFFFCC">
    <TD WIDTH="29%">
    <DIV ALIGN="RIGHT"><FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="-1">e-mail:
    </FONT></DIV>
    </TD>
    <TD WIDTH="71%">
    <INPUT TYPE="text" NAME="Email" SIZE="25">
    </TD>
    </TR>
    <TR BGCOLOR="#FFFFCC">
    <TD WIDTH="29%">
    <DIV ALIGN="right"><FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="-1">phone:
    </FONT></DIV>
    </TD>
    <TD WIDTH="71%">
    <INPUT TYPE="text" NAME="Phone" SIZE="25">
    <FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="-2">
    </FONT></TD>
    </TR>
    <TR BGCOLOR="#FFFFCC">
    <TD WIDTH="29%">
    <DIV ALIGN="RIGHT"><FONT FACE="Verdana, Arial, Helvetica, sans-serif" SIZE="-1">fax:
    </FONT></DIV>
    </TD>
    <TD WIDTH="71%">
    <INPUT TYPE="text" NAME="Fax" SIZE="25">
    </TD>
    </TR>
    </TABLE>
    <BR>
    <TABLE CELLSPACING="0" CELLPADDING="0" BORDER="0" ALIGN="center" WIDTH="58%" MM_NOCONVERT="TRUE">
    <TR>
    <TD HEIGHT="65" COLSPAN="2" VALIGN="top">
    <DIV ALIGN="center"><BR>
    <INPUT NAME="submit" TYPE="SUBMIT" VALUE="Submit">
    <INPUT NAME="reset" TYPE="RESET" VALUE="Reset All">
    </DIV>
    </TD>
    </TR>
    </TABLE>
    </FORM>
    </BODY>
    </HTML>

  5. #5
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Alright,

    This script (if you'd like a nice and advanced one), will consist of two pages. The first page will gather the form information, and the second page will simply send the e-mail. I could do it in one but it becomes a tad complicated and it's easier to understand this way.

    I'll work on it this morning. I should have it back to you by noon today, but perhaps later.
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  6. #6
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Okay. Here we go:

    Before I begin, I want to make sure you know that this requires a Windows NT Server running IIS, that has ASP support, and that has the CDONTS Component (a standard ASP component) installed. Also, please note that most description for code bits are BELOW the code bit.

    For starters, change the form action statement (below):
    Code:
    <FORM method=POST action="http://www.myserver.com/bin/mailto.exe">
    To whatever ASP Page you're using. I changed it to "http://www.myserver.com/sendmail.asp". This should be all that's required on this page.

    Now, for the hard stuff. We start out on sendmail.asp with the following code:
    Code:
    <%@LANGUAGE="VBScript"%>
    <%Option Explicit%>
    I included it just in case you're very new to ASP. Firstly, it tells ASP that you'll be using VBScript, which is more reliable than JavaScript (when working with ASP). The second line, "Option Explicit", tells the web page that it must check all your variables that are used to store information before proceeding. This prevents a lot of errors due to the misspelling of variable names, and makes coding a heck of a lot easier.
    Code:
    <%dim varTraveler, varDivision, varSuperviser, varEMail, varPhone, varFax, varNewMail, varNewLine, varTitle, varBody, varTo, varCC, varFrom%>
    This dims all of our variables that we will be using. This may seem like a lot, but it proves better in the long run.
    Code:
    <%set varNewMail = Server.CreateObject("CDONTS.NewMail")%>
    This sets a variable to an object. Whenever we reference varNewMail, we're talking about the e-mail object now.
    Code:
    <%varTraveler = Request.Form("Traveler")
    varSupervisor = Request.Form("Supervisor")
    varDivision = Request.Form("Division")
    varEMail = Request.Form("Email")
    varPhone = Request.Form("Phone")
    varFax = Request.Form("Fax")%>
    This will set all of the variables that you need equal to those that were submitted in the form that was filled out.
    Code:
    <%varNewLine = Chr(13) & Chr(10)%>
    The line above sets a "NewLine" variable. This will be used later on when sending the mail.
    Code:
    <%varTo = "info@mydomain.com"%>
    This is almost self-explanitory. We're setting the variable of who this mail will be sent to. Put your own e-mail address there.
    Code:
    <%Select Case varEMail
    Case "Don"
         varCC = "don@domain.com"
    Case "Art"
         varCC = "art@domain.com"
    Case "Bernie"
         varCC = "Bernie@domain.com"
    End Select
    %>
    This sets the Carbon-Copy variable based on who's selected from the drop-down box.
    Code:
    <%varFrom = "any-email-address@domain.com"%>
    This says who the e-mail is from. You may want to set it to something easily recognizable, such as "NewTraveler@yourdomain.com". This way, when you see anything from that address, you know it's the form submission. It also makes filtering those e-mails and sorting them much easier.
    Code:
    <%varTitle = "A New Traveler!"%>
    The code above sets the title of the E-Mail. (who would've guessed that?).

    Now, for the hard part. You're going to see a very long line of text below. It is actually the body of your e-mail, fit tightly into one line. It is this way because, well, you can't just type enters and spaces and have it format the e-mail for you. This is why we set the 'varNewLine' variable earlier. It is the equivilent of htiting the enter key once. Check out the code below. I'll explain, I promise:
    Code:
    <%varBody = "We have a new traveler! Information Below:" & varNewLine & varNewLine & "Traveler Name: " & varTraveler & varNewLine & "Supervisor: " & varSupervisor & varNewLine & "Divison: " & varDivison & varNewLine & "E-Mail: " & varEMail & varNewLine & "Phone #: " & varPhone & varNewLine and "Fax #: " & varFax & varNewLine & varNewLine & "Any other specific text that you want to add goes here."%>
    I'm sure this seems like a lot, but all it does is send your e-mail with some text, then some nicely formatted information, and then some more text. That's all.

    Now, we're drawing near the last few steps. Remember the E-Mail object that we created? Well, now we set the values for it to the values we've entered:
    Code:
    <%varNewMail.To = varTo
    varNewMail.From = varFrom
    varNewMail.CC = varCC
    varNewMail.Subject = varTitle
    varNewMail.Body = varBody%>
    Now for the last line in the e-mail script, sending it on its way:
    Code:
    <%varNewMail.Send%>
    Think we're done? We're not. After that, you can put any HTML code that you'd like for like a "Thank you, your form has been e-mailed", etc., etc. After you've done that, and after the ending "</HTML>" tag, you will enter this code:
    Code:
    <%set VarNewMail = Nothing%>
    The code above frees up server resources to keep your site running smoothly.

    That should be it. I haven't tested this code, and it is prone to misspellings, so I would double-check it yourself, and ask another of our resident ASP 'Gurus' to check it as well. The full, unadulterated code will be posted after this post. That code has no explaination and you should be able to copy/paste.

    I hope this posts helps. If you like it, or find it useful, don't hesitate to give me a SitePoint.
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  7. #7
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The full, unadulterated code:
    Code:
    <%@LANGUAGE="VBScript"%>
    <%Option Explicit%>
    <%dim varTraveler, varDivision, varSuperviser, varEMail, varPhone, varFax, varNewMail, varNewLine, varTitle, varBody, varTo, varCC, varFrom
    set varNewMail = Server.CreateObject("CDONTS.NewMail")
    varTraveler = Request.Form("Traveler")
    varSupervisor = Request.Form("Supervisor")
    varDivision = Request.Form("Division")
    varEMail = Request.Form("Email")
    varPhone = Request.Form("Phone")
    varFax = Request.Form("Fax")
    varNewLine = Chr(13) & Chr(10)
    varTo = "info@mydomain.com"
    Select Case varEMail
    Case "Don"
         varCC = "don@domain.com"
    Case "Art"
         varCC = "art@domain.com"
    Case "Bernie"
         varCC = "Bernie@domain.com"
    End Select
    varFrom = "any-email-address@domain.com"
    varTitle = "A New Traveler!"
    varBody = "We have a new traveler! Information Below:" & varNewLine & varNewLine & "Traveler Name: " & varTraveler & varNewLine & "Supervisor: " & varSupervisor & varNewLine & "Divison: " & varDivison & varNewLine & "E-Mail: " & varEMail & varNewLine & "Phone #: " & varPhone & varNewLine and "Fax #: " & varFax & varNewLine & varNewLine & "Any other specific text that you want to add goes here."
    varNewMail.To = varTo
    varNewMail.From = varFrom
    varNewMail.CC = varCC
    varNewMail.Subject = varTitle
    varNewMail.Body = varBody
    varNewMail.Send
    %>
    <HTML>
    <HEAD><TITLE>Title of Page</TITLE></HEAD>
    <BODY>
    Your form was e-mailed successfully.
    </BODY>
    </HTML>
    <%set varNewMail = Nothing%>
    And there you have it!
    Hopefully I was able to give you a better understanding of how this works in ASP. If not, at least you got the code, eh?

    Just put the code in a sendmail.asp file, put it in the right directory, and things should take care of themselves. Glad to be of assistence.
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  8. #8
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, you should now remove all those hidden form fields. You don't need them. You're in the big time.
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  9. #9
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by goober
    Also, you should now remove all those hidden form fields. You don't need them. You're in the big time.
    Fantastic!

    Almost done, just can't seem to get past this error message.


    *****************>>
    Microsoft VBScript runtime error '800a000d'
    Type mismatch: '[string: "Traveler Name: Sup"]'
    /sendmail.asp, line 23
    *****************>>

    1.-http://support.microsoft.com/support/kb/articles/Q244/7/58.ASP
    2.- http://support.microsoft.com/support.../Q244/7/58.ASP

    Any help would be greatly appreciated.

    Thanks

  10. #10
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    hmiller,

    There's a couple of typos in goobers script. Check the instances of the variables varSupervisor and varDivision.

    Also, on the line that sets the body text change the following:
    Code:
    "Phone #: " & varPhone & varNewLine and "Fax #: "
    to:
    Code:
    "Phone #: " & varPhone & varNewLine & "Fax #: "
    The code below has combined your form page and goobers script and worked when tested. If you have problems try using the code below as a test.

    Code:
    <%@LANGUAGE="VBScript"%>
    <% Option Explicit %>
    <%
    Response.Buffer = True
    
    Sub DisplayTravelForm()
    %>
    	<form method=post action="<%=Request.ServerVariables("SCRIPT_NAME")%>"> 
    		<table width="58%" border="0" mm_noconvert="TRUE" align="CENTER"> 
    		<tr valign="middle"> 
    			<td class="travelformlabel"><b>Traveler:</b></td>
    			<td class="travelformvalue"> 
    			<select class="formselect" name="Traveler"> 
    				<option value="" selected>Select a name</option>
    				<option value="Joe">Joe</option>
    				<option value="Jane">Jane</option>
    				<option value="Rob">Rob</option>
    			</select>
    			</td>
    		</tr> 
    		<tr> 
    			<td class="travelformlabel">Your supervisor:</td> 
    			<td class="travelformvalue"> 
    				<select class="formselect" name="Supervisor"> 
    					<option value="" selected>Select a name</option> 
    					<option value="Don">Don</option> 
    					<option value="Art">Art</option> 
    					<option value="Bernie">Bernie</option> 
    				</select> 
    			</td> 
    		</tr> 
    		<tr> 
    			<td class="travelformlabel">division: </td>
    			<td class="travelformvalue"> 
    				<input class="formtext" type="text" name="Division" size="25"> 
    			</td> 
    		</tr> 
    		<tr> 
    			<td class="travelformlabel">e-mail: </td> 
    			<td class="travelformvalue"> 
    				<input class="formtext" type="text" name="Email" size="25"> 
    			</td> 
    		</tr> 
    		<tr> 
    			<td class="travelformlabel">phone: </td> 
    			<td class="travelformvalue"> 
    				<input class="formtext" type="text" name="Phone" size="25"> 
    			</td> 
    		</tr> 
    		<tr> 
    			<td class="travelformlabel">fax: </td> 
    			<td class="travelformvalue"> 
    				<input class="formtext" type="text" name="Fax" size="25"> 
    			</td> 
    		</tr> 
    		</table> 
    		<br> 
    		<table cellspacing="0" cellpadding="0" border="0" align="center" width="58%" mm_noconvert="TRUE"> 
    			<tr> 
    				<td style="text-align: center" height="65" colspan="2" valign="top"> 
    					<input class="formbutton" name="submit" type="SUBMIT" value="Submit"> 
    					<input class="formbutton" name="reset" type="RESET" value="Reset All"> 
    				</td> 
    			</tr> 
    		</table>
    		<input type="hidden" name="flag" value="2">
    		</form> 
    <%
    End Sub
    
    Sub ProcessTravelEmail()
    
    Dim varTraveler
    Dim varDivision
    Dim varSupervisor
    Dim varEMail
    Dim varPhone
    Dim varFax
    Dim varNewMail
    Dim varTitle
    Dim varBody
    Dim varTo
    Dim varCC
    Dim varFrom
    Dim strSuccessMsg
    Dim strFailMsg
    Dim strFlag
    	
    	On Error Resume Next
    	
    	strFlag = Request.Form("flag")
    	
    	If strFlag <> "2" Then
    		'Display the travel form
    		Call DisplayTravelForm
    	Else
    		'Process the form and send email
    		
    		'--Get the variables from the form
    		varTraveler = Request.Form("Traveler")
    		varSupervisor = Request.Form("Supervisor")
    		varDivision = Request.Form("Division")
    		varEMail = Request.Form("Email")
    		varPhone = Request.Form("Phone")
    		varFax = Request.Form("Fax")
    		
    		
    		'--Set up the variables to be used for success/fail messages
    		strSuccessMsg = "Thanks, you email has been sent successfully."
    		strFailMsg = "Sorry, there was a problem sending your email. Please try again."
    		
    		'--Set up the variables to be used in email
    		'varTo = "info@mydomain.com"
    		'varFrom = "any-email-address@domain.com"
    		
    		Select Case varEMail
    			Case "Don"
    			     varCC = "don@domain.com"
    			Case "Art"
    			     varCC = "art@domain.com"
    			Case "Bernie"
    			     varCC = "Bernie@domain.com"
    		End Select
    			
    		varTitle = "A New Traveler!"
    		varBody = "We have a new traveler! Information Below:" &  vbCrLf &  vbCrLf & _
    							"Traveler Name: " & varTraveler & vbCrLf & _
    							"Supervisor: " & varSupervisor &  vbCrLf & _
    							"Divison: " & varDivision &  vbCrLf & _
    							"E-Mail: " & varEMail &  vbCrLf & _
    							"Phone #: " & varPhone &  vbCrLf & _
    							"Fax #: " & varFax &  vbCrLf & vbCrLf & _
    							"Any other specific text that you want to add goes here."
    		
    		'--Create the email
    		Set varNewMail = Server.CreateObject("CDONTS.NewMail")
    		varNewMail.To = varTo
    		varNewMail.From = varFrom
    		varNewMail.CC = varCC
    		varNewMail.Subject = varTitle
    		varNewMail.Body = varBody
    		varNewMail.Send
    		'Free resources
    		Set varNewMail = Nothing
    		
    		'If no errors occured then display 'success' message
    		'otherwise redisplay the travel form and display the 'fail' message
    		If Err.Number = 0 Then
    			Response.Write "<p>" & strSuccessMsg & "</p>"
    		Else
    			Call DisplayTravelForm
    			'Display a message telling email failed
    			Response.Write "<p>" & strFailMsg & "</p>"
    			'Response.Write "<p>" & Err.Number & " " & Err.Description & "</p>"
    		End If
    	End If
    	
    End Sub
    
    %>
    <html> 
    <head> 
    	<title>Form</title>
    	<style>
    		td.travelformlabel {
    			background-color: #ffffcc;
    			font-family: Verdana, Arial, sans-serif;
    			font-size: 11px;
    			color: #000000;
    			width: 30%;
    			text-align: right;
    		}
    		td.travelformvalue {
    			background-color: #ffffcc;
    			font-family: Verdana, Arial, sans-serif;
    			font-size: 11px;
    			color: #000000;
    			width: 70%
    		}
    		.formtext, .formselect, .formbutton {
    			font-family: Verdana, Arial, sans-serif;
    			font-size: 11px;
    			color: #000000;
    		}
    	</style>
    </head>
    
    <body vlink="#660066" alink="#669900" link="#3333ff" bgcolor="#ffffff" leftmargin="4" topmargin="0" marginheight="0" marginwidth="4" text="#000000"> 
    
    <% Call ProcessTravelEmail %> 
    	
    </body> 
    </html>
    Shane
    Last edited by shane; Feb 19, 2001 at 07:28.

  11. #11
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shane,

    Thanks for correcting the typos! I knew there were some, but I had scanned and scanned and decided to leave it up to others.

    Hmiller > Shane re-did this script to be in one page instead of two (if I'm correct -- i only briefly scanned). Either Style will work, it's simply a matter of preference.

    Thanks again, Shane!
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  12. #12
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shane,

    Tried the script and seems to work O.K., get a success message after submiting. Only problem is I do not receive any e-mail. Settings TO: where changed to my correct e-mail address as well as CC:

    I put the script into one page and also split in two, no luck yet.

    Thanks in advance

    Originally posted by shane
    hmiller,

    There's a couple of typos in goobers script. Check the instances of the variables varSupervisor and varDivision.

    Also, on the line that sets the body text change the following:
    Code:
    "Phone #: " & varPhone & varNewLine and "Fax #: "
    to:
    Code:
    "Phone #: " & varPhone & varNewLine & "Fax #: "
    The code below has combined your form page and goobers script and worked when tested. If you have problems try using the code below as a test.

    Code:
    <%@LANGUAGE="VBScript"%>
    <% Option Explicit %>
    <%
    Response.Buffer = True
    
    Sub DisplayTravelForm()
    %>
    	<form method=post action="<%=Request.ServerVariables("SCRIPT_NAME")%>"> 
    		<table width="58%" border="0" mm_noconvert="TRUE" align="CENTER"> 
    		<tr valign="middle"> 
    			<td class="travelformlabel"><b>Traveler:</b></td>
    			<td class="travelformvalue"> 
    			<select class="formselect" name="Traveler"> 
    				<option value="" selected>Select a name</option>
    				<option value="Joe">Joe</option>
    				<option value="Jane">Jane</option>
    				<option value="Rob">Rob</option>
    			</select>
    			</td>
    		</tr> 
    		<tr> 
    			<td class="travelformlabel">Your supervisor:</td> 
    			<td class="travelformvalue"> 
    				<select class="formselect" name="Supervisor"> 
    					<option value="" selected>Select a name</option> 
    					<option value="Don">Don</option> 
    					<option value="Art">Art</option> 
    					<option value="Bernie">Bernie</option> 
    				</select> 
    			</td> 
    		</tr> 
    		<tr> 
    			<td class="travelformlabel">division: </td>
    			<td class="travelformvalue"> 
    				<input class="formtext" type="text" name="Division" size="25"> 
    			</td> 
    		</tr> 
    		<tr> 
    			<td class="travelformlabel">e-mail: </td> 
    			<td class="travelformvalue"> 
    				<input class="formtext" type="text" name="Email" size="25"> 
    			</td> 
    		</tr> 
    		<tr> 
    			<td class="travelformlabel">phone: </td> 
    			<td class="travelformvalue"> 
    				<input class="formtext" type="text" name="Phone" size="25"> 
    			</td> 
    		</tr> 
    		<tr> 
    			<td class="travelformlabel">fax: </td> 
    			<td class="travelformvalue"> 
    				<input class="formtext" type="text" name="Fax" size="25"> 
    			</td> 
    		</tr> 
    		</table> 
    		<br> 
    		<table cellspacing="0" cellpadding="0" border="0" align="center" width="58%" mm_noconvert="TRUE"> 
    			<tr> 
    				<td style="text-align: center" height="65" colspan="2" valign="top"> 
    					<input class="formbutton" name="submit" type="SUBMIT" value="Submit"> 
    					<input class="formbutton" name="reset" type="RESET" value="Reset All"> 
    				</td> 
    			</tr> 
    		</table>
    		<input type="hidden" name="flag" value="2">
    		</form> 
    <%
    End Sub
    
    Sub ProcessTravelEmail()
    
    Dim varTraveler
    Dim varDivision
    Dim varSupervisor
    Dim varEMail
    Dim varPhone
    Dim varFax
    Dim varNewMail
    Dim varTitle
    Dim varBody
    Dim varTo
    Dim varCC
    Dim varFrom
    Dim strSuccessMsg
    Dim strFailMsg
    Dim strFlag
    	
    	On Error Resume Next
    	
    	strFlag = Request.Form("flag")
    	
    	If strFlag <> "2" Then
    		'Display the travel form
    		Call DisplayTravelForm
    	Else
    		'Process the form and send email
    		
    		'--Get the variables from the form
    		varTraveler = Request.Form("Traveler")
    		varSupervisor = Request.Form("Supervisor")
    		varDivision = Request.Form("Division")
    		varEMail = Request.Form("Email")
    		varPhone = Request.Form("Phone")
    		varFax = Request.Form("Fax")
    		
    		
    		'--Set up the variables to be used for success/fail messages
    		strSuccessMsg = "Thanks, you email has been sent successfully."
    		strFailMsg = "Sorry, there was a problem sending your email. Please try again."
    		
    		'--Set up the variables to be used in email
    		'varTo = "info@mydomain.com"
    		'varFrom = "any-email-address@domain.com"
    		
    		Select Case varEMail
    			Case "Don"
    			     varCC = "don@domain.com"
    			Case "Art"
    			     varCC = "art@domain.com"
    			Case "Bernie"
    			     varCC = "Bernie@domain.com"
    		End Select
    			
    		varTitle = "A New Traveler!"
    		varBody = "We have a new traveler! Information Below:" &  vbCrLf &  vbCrLf & _
    							"Traveler Name: " & varTraveler & vbCrLf & _
    							"Supervisor: " & varSupervisor &  vbCrLf & _
    							"Divison: " & varDivision &  vbCrLf & _
    							"E-Mail: " & varEMail &  vbCrLf & _
    							"Phone #: " & varPhone &  vbCrLf & _
    							"Fax #: " & varFax &  vbCrLf & vbCrLf & _
    							"Any other specific text that you want to add goes here."
    		
    		'--Create the email
    		Set varNewMail = Server.CreateObject("CDONTS.NewMail")
    		varNewMail.To = varTo
    		varNewMail.From = varFrom
    		varNewMail.CC = varCC
    		varNewMail.Subject = varTitle
    		varNewMail.Body = varBody
    		varNewMail.Send
    		'Free resources
    		Set varNewMail = Nothing
    		
    		'If no errors occured then display 'success' message
    		'otherwise redisplay the travel form and display the 'fail' message
    		If Err.Number = 0 Then
    			Response.Write "<p>" & strSuccessMsg & "</p>"
    		Else
    			Call DisplayTravelForm
    			'Display a message telling email failed
    			Response.Write "<p>" & strFailMsg & "</p>"
    			'Response.Write "<p>" & Err.Number & " " & Err.Description & "</p>"
    		End If
    	End If
    	
    End Sub
    
    %>
    <html> 
    <head> 
    	<title>Form</title>
    	<style>
    		td.travelformlabel {
    			background-color: #ffffcc;
    			font-family: Verdana, Arial, sans-serif;
    			font-size: 11px;
    			color: #000000;
    			width: 30%;
    			text-align: right;
    		}
    		td.travelformvalue {
    			background-color: #ffffcc;
    			font-family: Verdana, Arial, sans-serif;
    			font-size: 11px;
    			color: #000000;
    			width: 70%
    		}
    		.formtext, .formselect, .formbutton {
    			font-family: Verdana, Arial, sans-serif;
    			font-size: 11px;
    			color: #000000;
    		}
    	</style>
    </head>
    
    <body vlink="#660066" alink="#669900" link="#3333ff" bgcolor="#ffffff" leftmargin="4" topmargin="0" marginheight="0" marginwidth="4" text="#000000"> 
    
    <% Call ProcessTravelEmail %> 
    	
    </body> 
    </html>
    Shane

  13. #13
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Sorry!

    When I was testing the script I commented out a couple of lines and didn't remove the comments.

    Code:
    '--Set up the variables to be used in email
    'varTo = "info@mydomain.com"
    'varFrom = "any-email-address@domain.com"
    Should have been:
    Code:
    '--Set up the variables to be used in email
    varTo = "info@mydomain.com"
    varFrom = "any-email-address@domain.com"
    Notice the extra ' in the first piece of code.

    I've put the form and code into one page because it was easier to test. It also makes it easier to check for any errors when creating and sending the email. If any errors occur the form is redisplayed and a 'fail' message is displayed.

    I also changed your form slightly so that it uses css more. This is a personal thing but I find it easier to read the html. Users without browsers supporting css will still be able to use it ok.

    Let us know how you get on.

    Shane

  14. #14
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shane,

    boy, don't i know that mistake all too well

    Thanks for assisting me with this post, by the way!
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  15. #15
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shane,

    I did receive e-mail after deleting the comments as you posted. Only problem is I still do not get a CC of this
    form to the selected supervisor.

    I am missing something?

    Thanks

    Originally posted by shane
    Sorry!

    When I was testing the script I commented out a couple of lines and didn't remove the comments.

    Code:
    '--Set up the variables to be used in email
    'varTo = "info@mydomain.com"
    'varFrom = "any-email-address@domain.com"
    Should have been:
    Code:
    '--Set up the variables to be used in email
    varTo = "info@mydomain.com"
    varFrom = "any-email-address@domain.com"
    Notice the extra ' in the first piece of code.

    I've put the form and code into one page because it was easier to test. It also makes it easier to check for any errors when creating and sending the email. If any errors occur the form is redisplayed and a 'fail' message is displayed.

    I also changed your form slightly so that it uses css more. This is a personal thing but I find it easier to read the html. Users without browsers supporting css will still be able to use it ok.

    Let us know how you get on.

    Shane

  16. #16
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try making sure that the 'varCC' variable is not misspelled anywhere. Also, make sure this line of code is present and looks like the code below:
    Code:
    <%varNewMail.CC = varCC%>
    That should take care of it. If not, that's just odd. Try again!
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  17. #17
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    We've made a slight error in the code. Change the following bit of code:

    Code:
    Select Case varEMail
      Case "Don" varCC = "don@domain.com"
      Case "Art" varCC = "art@domain.com"
      Case "Bernie" varCC = "Bernie@domain.com"
    End Select

    to:

    Code:
    Select Case LCase(varSupervisor)
      Case "don"    varCC = "don@domain.com"
      Case "art"    varCC = "art@domain.com"
      Case "bernie" varCC = "Bernie@domain.com"
      Case Else     varCC = "defaultsuper@domain.com"
    End Select
    This should do the trick.

    Goober->It's been a pleasure. btw I like the new avatar. And that's coming from an Englishman

    Shane

  18. #18
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Shane,

    ah-ha! Alright, I knew there had to be something.

    Yes, shane it was definitely a pleasure.

    Wow, an Englishmen complimenting an Irishmen. Well, I'll just have to bomb you.

    Sorry for the morbid humor, hehe. Thanks again shane!
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)

  19. #19
    SitePoint Member
    Join Date
    Feb 2001
    Posts
    10
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Goober & Shane,

    Thanks for all your help, the script works great!!!

  20. #20
    Say WHA?! goober's Avatar
    Join Date
    Sep 2000
    Location
    United States
    Posts
    1,921
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    *beaming smile*

    You know, this is what SitePoint is all about. Teamwork, helping people solve problems....*sniff*.

    Anyways, I'm glad it works. And Shane, I never would've been able to do it without you. Thanks!
    Sean Killeen [LinkedIn] [Twitter] [Web]

    Warning: Reality.sys corrupted. Universe halted. Reboot? (Y/N)


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •