Solved

Send ASP email using CDOSYS with HTML body which merges both form fields and DB fields

Posted on 2009-05-09
5
881 Views
Last Modified: 2012-06-27
I am having a problem with an ASP form. We use the form to send emails to clients through our support intranet. The form has a few fields and when it is submitted it should send an email to the client and copy us in as well as adding the form fields to the support intranet database.

It all works fine but now we want to merge a field from the database with the email body before it is sent.

I dont know how to pull these database fields in to the code for the email. Can anyone assist?

The field I am trying to add on to the end of the HTML email body is:
Users.Fields.Item("HTMLSignature").Value
The recordset is called Users and the field is called HTMLSignature

Just to say that the code works fine EXCEPT for that i can't merge the contents of the HTMLSignature field with the emailBody variable....

the error i get is:

Microsoft VBScript runtime error '800a01a8'

Object required: ''

/add_incident_email_send.asp, line 73

Line 73 is the line starting emailBody=
emailSubject = "Support Incident: " &  Request.Form("IncidentID") & " - " & Request.Form("IncidentTitle")
emailTo = Request.Form("emailTo")
emailBody = Request.Form("ActionDetail") & Users.Fields.Item("HTMLSignature").Value
 
Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = emailSubject
objMessage.From = "Support @ Our Company<support@ourcompany.com>" 
objMessage.To = emailTo
objMessage.HTMLBody = emailBody
 
objMessage.Send

Open in new window

0
Comment
Question by:it4business
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 24346576
the only way that you can accomplish this is to have a query done.
Either from the Form before this page that has that information in it.

Say that your <Form> has this in it
<input type="hidden" name="HTMLSignature" value="<%=Users.Fields.Item("HTMLSignature").Value%>"/>

Now.
In your Mail script would look something like this.
(I believe that the code will compile without error, as I cannot remember if something else needs to seperate the 2 Form Values....)

Good Luck
Carrzkiss
emailSubject = "Support Incident: " &  Request.Form("IncidentID") & " - " & Request.Form("IncidentTitle")
emailTo = Request.Form("emailTo")
emailBody = Request.Form("ActionDetail") & request.form("HTMLSignature")
Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = emailSubject
objMessage.From = "Support @ Our Company<support@ourcompany.com>" 
objMessage.To = emailTo
objMessage.HTMLBody = emailBody
 
objMessage.Send

Open in new window

0
 

Author Comment

by:it4business
ID: 24347961
Thank you for that. Yes that works perfectly but I had to take all the " out of the field value because otherwise the page displayed the HTML signature where I placed the hidden field! works great though.

Do you think it is possible to do it without the hidden field? It seems inefficient and I wonder if it is possible to use the value directly from the recordset? Can the VBScript for sending the emails only process values from a form? I guess I could make a session variable but that doesnt seem the right way.

Sorry if the request seems awkward, I am trying to learn what is/isn't possible as much as getting a solution!
0
 
LVL 31

Accepted Solution

by:
Wayne Barron earned 250 total points
ID: 24349076
yep.
If the value has a associated record then something like this on the Mail script end.

send.asp?id=1
<% sql = "SELECT ID, HTMLSignature from Table1 WHERE ID="&Request.QueryString("id")&""
rs1.open sql, conn
%>

Now in you script you would do this.

As long as the ID matches the one that you want, you are good to go.
So in the
<Form Action="send.asp?id=1">

Good Luck
Carrzkiss
emailSubject = "Support Incident: " &  Request.Form("IncidentID") & " - " & Request.Form("IncidentTitle")
emailTo = Request.Form("emailTo")
emailBody = Request.Form("ActionDetail") & request.querystring("HTMLSignature")
Set objMessage = CreateObject("CDO.Message") 
objMessage.Subject = emailSubject
objMessage.From = "Support @ Our Company<support@ourcompany.com>" 
objMessage.To = emailTo
objMessage.HTMLBody = emailBody
 
objMessage.Send

Open in new window

0
 

Author Closing Comment

by:it4business
ID: 31579836
worked great - didnt realise i hadn't already accepted the solution!
0
 
LVL 31

Expert Comment

by:Wayne Barron
ID: 25563256
Yep, has been a while, 5 months actually :=)~.
Glad that it worked for you.
Have a good one
Carrzkiss

Author Comments:
worked great - didnt realise i hadn't already accepted the solution!
0

Featured Post

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Mobile apps - web/native or hybrid? 1 72
Hide and Unhide Table 6 27
output in HTML in Powershell 5 28
Increase image taller on inner pages 2 18
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question