The SitePoint Forums have moved.

You can now find them here.
This forum is now closed to new posts, but you can browse existing content.
You can find out more information about the move and how to open a new account (if necessary) here.
If you get stuck you can get support by emailing forums@sitepoint.com

If this is your first visit, be sure to
check out the FAQ by clicking the
link above. You may have to register
before you can post: click the register link above to proceed. To start viewing messages,
select the forum that you want to visit from the selection below.

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?

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.

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.

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.

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.

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:

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.

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.

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.