ASP Is Fun

Learning ASP
Free Course
Basics
Functions
SQL Commands
Sample Code

Servers / Setup
Host Reviews
Server Setup
Error Tips

Contract ASP
Development

Intro to ASP



 


Sending HTML Mail with ASP



HTML mail is in essence a mail message that has HTML commands in it, instead of just text. It allows the mail message to show images, provide links, and look pretty.

It can get complicated to send a well formatted HTML message. So start with the basics. Read up on Sending a Mail Message with ASP and make SURE you can successfully send messages in regular text. You only want to have to troubleshoot one problem at a time!

OK, so your mail is going out properly. Now you want to send a message with say BOLD LETTERS in it. Again, start small so if you hit a problem you can easily figure out what it is.

Just like before, start out by setting up the to-email, the from-email, and the subject line:

FromEmail = "webmaster@aspisfun.com"
ToEmail = "destination@aspisfun.com"
Subject = "Here is your order confirmation"

next, set up your actual email message. Now that it will be a HTML message, remember to use the P and/or BR commands to separate your paragraps.

EmailMessage = "Thank you for order!<BR>" & CHR(13) & _
"Here are the details of your order.<BR>" & CHR(13) & _
"<B>This Detail Is In Bold</B><BR>" & CHR(13) & _
"...details...<BR>" & CHR(13)

Note that the CHR(13)s just put hard returns after the lines, but in HTML hard returns are ignored.

OK you have your message, with line breaks and a bold part. Now you have to tell the mailer that you want this to be sent as a HTML message and not just as a text message. Otherwise the end user will see lots of HTML commands instead of seeing a pretty message.

Dim objMail
set objMail = CreateObject("CDONTS.NewMail")
Impt = 1
objMail.MailFormat = 0
objMail.BodyFormat = 0

The MailFormat and BodyFormat are what indicate this is a HTML message. Finally, like all good HTML, the HTML has to start and end with a HTML and BODY tag. So adjust your email message to have the proper wrapper.

FinalMessage = "<HTML><BODY> " & _
"<!DOCTYPE HTML PUBLIC ""-//IETF//DTD HTML//EN"">" & _
EmailMessage & "</BODY></HTML>"

Now send the message and close the connection

objMail.Send FromEmail,ToEmail,Subject,FinalMessage,Impt
set objMail = Nothing

There you go! Once you get a basic HTML message going out, you can enhance it with colors, graphics, and much more - just about anything you can do in HTML.

ASP Mail Code and Troubleshooting


ASP Main Page | ASP Ebooks | Free ASP Course | Contact Lisa
All content copyright © 2008 Minerva WebWorks LLC. All rights reserved.

Italian Wedding


Free Newsletter!

Ebooks
Intro to ASP
ASP SQL DB
Members
Shopping


Introduction to ASP

Romance Tips
Irish Romance
Italian Romance
French Romance

ASP Poll
How do you handle 500 errors?
I don't
Page does nothing
Displays error
Emails error