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.
Sending a Mail Message with ASP
Introduction to ASP Ebook Download this ebook to get everything you need to know about learning ASP - from a step by step tutorial to function lists, sample code, common errors and solutions, and much more! 101 pages. |