hartski 0 Newbie Poster

Hello! New to the site today....
Hoping to get some help.

I have designed a site at work which has a form for staff to send suggestions, and it auto emails a number of people using CDONTS on an ASP page.

Its a very basic 'Name', 'Dept', 'Suggestion' form... however the format of the resulting email is very boring plain text and I want to use some HTML to make it look a bit more formalised, although I have no idea where to place any html formatting within the existing code to manipulate the look of the email.

my code is:

name=request("name")
	name = replace(name, chr(34), "")
	name = replace(name, chr(39), "")

dept=request("dept")
	dept = replace(dept, chr(34), "")
	dept = replace(dept, chr(39), "")

query=request("query")
	query = replace(query, chr(34), "")
	query = replace(query, chr(39), "")	

Set objSendMail = Server.CreateObject("CDONTS.NEWMAIL") 
	objSendMail.Subject = "Bright Sparks Suggestion" 
	objSendMail.From = "email address"
	objSendMail.To = "another email address"
	ObjSendMail.Body = request("name") & VBCrLf & request("dept") & VBCrLf & request("query")
	
              objSendMail.send
			
set rs = nothing			
Response.Redirect "thanks.html"

Now I assume I have to put something within the ObjSendMail.Body section but cannot get anything to work at all.

Can anyone get me started please?

thanks in advance

Dani AI

Generated

Hi — you can make the message HTML by sending an HTML body and using an email component that understands HTML. CDONTS is old and can be awkward for HTML; a more reliable approach on Windows is CDO (CDO.Message / CDOSYS) and its .HTMLBody property. Below is a compact ASP example that builds an HTML body, keeps a text fallback, and HTML-encodes user input so markup from the form does not break the message.

<%
Dim name, dept, query
name = Server.HTMLEncode(Request("name"))
dept = Server.HTMLEncode(Request("dept"))
query = Server.HTMLEncode(Request("query"))

Set objMsg = CreateObject("CDO.Message")
With objMsg
  .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
  .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
  .Configuration.Fields.Item("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25
  .Configuration.Fields.Update

  .From = "no-reply@yourdomain.com"
  .To = "recipient@yourdomain.com"
  .Subject = "Bright Sparks Suggestion"
  .TextBody = name & vbCrLf & dept & vbCrLf & query
  .HTMLBody = "<html><body><h2>Suggestion from " & name & "</h2><p><strong>Dept:</strong> " & dept & "</p><p>" & Replace(query, vbCrLf, "<br />") & "</p></body></html>"
  .Send
End With
Set objMsg = Nothing
%>

Quick tips: set the SMTP host/auth correctly (replace "localhost"), test by sending to yourself and viewing message source to confirm a text/html part, prefer inline CSS and simple markup (many mail clients strip complex CSS), and always HTML-encode user input rather than just stripping quotes. If you want, post your server details and I will adapt the sample to match your environment.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.