evening,
I could use some help with converting an order confirmation page using CDONTS to Jmail. The app is CharonCart 3. If you could be specific as to what exactly I need to change I would appreciate it.
Ualtered original related code is below. Thanks very much.
R
<%
'This is the part where we send out emails.
'There's a 101 different ways of doing it. I'm outlining 2 here.
'The first method uses CDOSYS. It's probably the best way of doing things but it can be flaky.
'Look at the line below, I've commented out the CDOSYS code. But you can use it if you want.
'SendEmail 'This line calls the function below and sends the email
'The second mthod is using CDONTS. Basically, the setting are in an XML file
'in the XML folder of this site. You can easily change the content of the email.
SendCdoEmail
'Start the functions
function SendEmail
'on error resume next 'This code will only work on a Win2k server.
Dim iMsg,iConf,Flds
Set iMsg = CreateObject("CDO.Message")
Set iConf = CreateObject("CDO.Configuration")
Set Flds = iConf.Fields
EmailPage="http://localhost/CartV3/Email.asp?OrderID=" & OrderID & "&CustomerID=" & CustomerID
'Response.Write(EmailPage)
'Response.End()
With Flds
' assume constants are defined within script file
.Item("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
.Item("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"
.Update
End With
With iMsg
Set .Configuration = iConf
.To = CustomerRS("CustomerEmail")
.From = "
[email protected]"
.Subject = "Charon Cart Order"
'.TextBody = "test"
.CreateMHTMLBody cstr(EmailPage)
.Send
End With
end function
function SendCdoEmail
Set objXML = Server.CreateObject("Microsoft.XMLDOM")
dim strBody
objXML.load(Server.MapPath("xml/orders_email.xml"))
set objNodeXML=objXML.documentElement
strFrom=objNodeXML.selectSingleNode("from").Text
strSubject=objNodeXML.selectSingleNode("subject"). Text
strBody=objNodeXML.selectSingleNode("body").Text
Set objXML = Nothing
'Response.Write mailbody(strBody)
'response.End()
Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
objCDOMail.From = strFrom
objCDOMail.To = CustomerRS("CustomerEmail")
objCDOMail.Subject = strSubject
objCDOMail.Body = mailbody(strBody)
objCDOMail.MailFormat=0
objCDOMail.BodyFormat=0
objCDOMail.Send
Set objCDOMail = Nothing
end function
'This function will replace the tokens in the XML file with contents of recordset
function mailbody(c)
tmpStr=c
tmpStr=replace(tmpStr,"#OrderID#",Session("OrderID "))
tmpStr=replace(tmpStr,"#OrderDetails#",OrderDetail s)
tmpStr=replace(tmpStr,"#OrderSummary#",OrderSummar y)
'Look at this next bit. In the XML file, the tokens are replaced by content from the recordset.
'So, if you've got #FirstName# in the XML file
'it will be replaced by FirstName content of recordset. Neat, eh?
for each fld in CustomerRS.Fields
if CustomerRS(fld.Name) & "" <> "" then
tmpStr=replace(tmpStr,"#" & fld.Name & "#",CustomerRS(fld.Name))
end if
next
mailbody=tmpStr
end function
function OrderDetails
tmpStr=""
while not CustomerOrderRS.eof
tmpStr=tmpStr & "ProductID - " & CustomerOrderRS("ProductID") & "<br>"
tmpStr=tmpStr & "Product - " & CustomerOrderRS("ProductName") & "<br>"
tmpStr=tmpStr & "Size - " & CustomerOrderRS("ProductSize") & "<br>"
tmpStr=tmpStr & "Colour - " & CustomerOrderRS("Colour") & "<br>"
tmpStr=tmpStr & "Quantity - " & CustomerOrderRS("Quantity") & "<br>"
tmpStr=tmpStr & "Unit Price - £" & formatnumber(CustomerOrderRS("UnitPrice"),2) & "<br>"
tmpStr=tmpStr & "==============" & "<br>" & "<br>"
CustomerOrderRS.movenext
wend
CustomerOrderRS.requery
OrderDetails=tmpStr
end function
function OrderSummary
tmpStr=""
tmpStr=tmpStr & "Subtotal - £" & formatnumber(OrdersRS("SubTotal"),2) & "<br>"
tmpStr=tmpStr & "Shipping - £" & formatnumber(OrdersRS("Freight"),2) & "<br>"
tmpStr=tmpStr & "Sales Tax - £" & formatnumber(OrdersRS("SalesTax"),2) & "<br>"
tmpStr=tmpStr & "Grandtotal - £" & formatnumber(OrdersRS("GrandTotal"),2) & "<br>" & "<br>"
OrderSummary=tmpStr
end function
%>
Don't know if you need this page for the above, orders_email.xml:
<?xml version="1.0"?>
<root>
<from>
[email protected]</from>
<to>customer</to>
<cc>
[email protected]</cc>
<subject>Order confirmation from Products website</subject>
<body><![CDATA[
<p>Order Confirmed with Thanks</p>
<p>Your Order No. is #OrderID#<p>
<p>Your order will be sent to:<br>
#FirstName# #LastName#<br>
#DeliveryAddress1# #DeliveryAddress2#<br>
#ShipCity# #ShipRegion# #ShipPostalCode#
</p>
<p>
#OrderDetails#
</p>
<p>
#OrderSummary#
</p>
]]></body>
</root>