[Classic] Email Form Processor

If you signed up with myhosting.com after October, 2004, a sample sendmail.asp script is located in your /cgi-bin folder. If you signed up prior to this date, please use the instructions below as we discontinued our support of the Bamboo ActiveX component. 

<%@LANGUAGE = VBSCRIPT%>

<html%>

<body%>

 

<%

 

'Collect form fields and their data

For Each x In Request.Form

message=message & x & ": " & Request.Form(x) & VBCrLf

Next

 

Create the JMail message Object

set msg = Server.CreateOBject( "JMail.Message" )

 

Set logging to true to ease any potential debugging

And set silent to true as we wish to handle our errors ourself

msg.Logging = true

msg.silent = true

 

Most mailservers require a valid email address for the sender

msg.From = "THIS SHOULD BE YOUR E-MAIL ADDRESS"

msg.FromName = "THIS SHOULD BE YOUR NAME"

 

Next we have to add some recipients.

msg.AddRecipient "YOUR FORM WILL BE SEND TO THE E-MAIL ADDRESS WRITTEN HERE"

 

The subject of the message

msg.Subject = "CHANGE THE SUBJECT LINE OF THE MESSAGE"

 

Note the use of VBCrLf to add linebreaks to our email

msg.Body = "Results of your web form:" & VBCrLf & VBCrLf & message & VBCrLf

 

To capture any errors which might occur, we wrap the call in an IF statement

Replace ENTERYOURDOMAINHERE with your domain name, like yourdomain.com

 

if not msg.Send("mail.ENTERYOURDOMAINHERE" ) then

This message is displayed if an error occurs

Response.write "An error occured. Please contact the webmaster of this site."

else

This message is displayed if the message has been sent successfully

Response.write "Thank you for your submission.... Your message has been delivered successfully."

end if

 

And we're done! the message has been sent.

%>

You can further customize the script to reflect the following issues/questions:

Question: I am having some trouble with the output from my forms processor. It does not seem to read the form objects from top to bottom, but instead returns them in a different order.

Answer:
This is the order the server receives the data from the browser. You can customize how the data is interpreted by changing sendmail.asp as follows:

For Each x In Request.Form

message=message & x & ": " & Request.Form(x) & VBCrLf

Next

(do not delete <% on top), then add:

name = Request.Form ("name")

surname = Request.Form ("surname")

message = message & "Name: " & name & VBCrLf

message = message & "Surname: " & surname & VBCrLf

The above example assumes you have two form fields with names "name" and "surname". It gets their values from the form fields, and assigns them to variables and inserts the values into the message. Likewise, add all your form field names that you want to include in the e-mail. This way you have the full control to the order.

Question: Exactly where in the order form HTML code is the CGI statement inserted so that we can receive orders from internet customers in our e-mail?

Answer: At the start of the form, refer to sendmail.asp in your form as:

<FORM NAME="yourformname" METHOD="post" ACTION="/cgi-bin/sendmail.asp">

Question: Can I customize my response after the form is submitted, instead of displaying simple text on the screen?

Answer: Yes you can. Instead of writing a simple text on screen, it can be redirected to another page. This can be done thru modifying the following code:

else

'This message is displayed if the message has been sent successfully

Response.write "Thank you for your submission.... Your message has been delivered successfully."

should be changed to

else

'This message is displayed if the message has been sent successfully

Response.Redirect ("../thankyou.html")

This change will display thankyou.html in your root directory after the message has been sent successfully.

NOTES: 

  1. To edit the sendmail.asp script you can use any text editor (eg. Notepad, Homesite, etc.)
  2. If you make any changes to the sendmail.asp script, don't forget to save the file and upload it back to the server.
  3. An error that is commonly done is not entering the sender and recipient email addresses in the sendmail.asp
  4. If you need further assistance with Jmail component used in this sample script, please see Jmail examples and manual:

http://tech.dimac.net/Products/w3JMail/Version43/Examples/ExampleStart.htm
http://tech.dimac.net/Products/w3JMail/Version43/Reference/RefStart.htm 

 

Was this article helpful?
0 out of 0 found this helpful