CoverYourASP --> Sending email from a form --> Part 3

Free membership

Join in the fun! Sign in
Member Services

Site navigation
Download the entire site!
Search my articles
Free Magazines
Browse the directory

Send me feedback
Buy my boxer shorts

Recommend this page
Printer-friendly page

Resources I recommend
Link to my site
Advertising slashed!
About your privacy
Legal stuff
Site statistics
197 active users
3191 visitors today
1996 pages today
(only part of today)
Tools I use

CoverYourASP
Copyright © 1999-2012 James Shaw.
All rights reserved.

ASP.NET Blog
RSS submissions
E-commerce

Now open source with SourceForge!

Making up the email

Having validated the email address, we need to make up the email and send it.

// make up the message body
var sBody = 'Message: "' + sMessage + '"\n\n';

if ( sFromName != '' )
   sBody += 'From: "' + sFromName + '".\n';

if ( sFromEmail != '' )
   sBody += 'Email: "' + sFromEmail + '".\n';

The body of the email is very simple in this case - this form is sending the information to me, so I just declare an sBody variable and add each data on a new line ( \n is a linefeed character in JavaScript, C, C++, etc ).

sBody += 'Browser: "' + Request.ServerVariables ( "HTTP_USER_AGENT" ) + '".\n';
sBody += 'IP address: "' + Request.ServerVariables ( "REMOTE_ADDR" ) + '".\n';

var dateToday = new Date();

sBody += 'Time: "' + dateToday.getHours() + ':' + dateToday.getMinutes() + '".\n';

Then, I add some more information to the email such as the user agent (browser) that was used, and the IP address of the sender. All this data and much more is available from the Request.ServerVariables collection.

Lastly, I add the time that the email was sent - note that this is server time, not the local client time...

// send Email with our generic function
SendEmail ( sFromEmail, 'Feedback@' + sHostDomain, '', sSubject, sBody );

...and send the email, again using a function defined in the utils/email.asp SSI.

Part 4: Using the SendEmail( ) function...

Featured sponsor
My favorite resources


Qualify for Free Trade Magazines

Free subscriptions to industry leading publications for those who qualify!


See my source code
wherever you see this icon...

You can also download the entire site source code for FREE!