?
Solved

Email formatting

Posted on 2005-03-02
9
Medium Priority
?
279 Views
Last Modified: 2012-05-05
Hi all,

I am using the below code to pick up purchase details on an ecommerce site.

A customer makes a purchase, upon clicking the submit button, a client receives email that summarizes purchases.

Such information include:

first name, last name,
address info and contact info.

Then the following info is also supplied:

Product Code   Product Name  Qty      Unit Price
value               value              value     value

Total: __________


So far, the code works fine except the formatting.

If a customer purchases only one item as shown above, the client can see it clearly but if the customer purchases more than one item as shown below, everything gets jumbled up and becomes harder to read.

Product Code   Product Name  Qty      Unit Price
value               value              value     value
    value       value          value                     value

Total: __________


The client's ISP accepts only jmail and cdosys, and I haven't used jmail before.

I was wondering if anyone knows of a way to format the code I have so far?

The code is below:

function mailMerchant(merchantmail,orderid,smtpServer)
      'get client info from DB
      set cmd = server.CreateObject("ADODB.Command")
      cmd.ActiveConnection = dbc
      cmd.CommandText = "qryOrderInfo"
      cmd.CommandType = adCmdStoredProc
      set param = cmd.CreateParameter("oid",adInteger,adParamInput,4)
      cmd.Parameters.Append param
      cmd("oid") = orderid

      'build message body strBody
      set rs = server.CreateObject("ADODB.recordset")
      set rs = cmd.Execute
      if not rs.eof then
            strBody = "Order Details for " & rs("cfirstname") & vbTab &  rs("clastname") & " on " & rs("odate") & vbCrLf & vbCrLf
            strBody = strBody & "Customer info:" & vbCrLf
            strBody = strBody & "First name: " & rs("cfirstname") & vbCrLf
            strBody = strBody & "Last Name: " & rs("clastname") & vbCrLf
            strBody = strBody & "Address1: " & rs("caddress") & vbCrLf
            strBody = strBody & "Address2: " & rs("caddress2") & vbCrLf
            strBody = strBody & "City: " & rs("ctown") & vbCrLf
            strBody = strBody & "State: " & rs("cstate") & vbCrLf
            strBody = strBody & "Zip Code: " & rs("czip") & vbCrLf
            strBody = strBody & "Country: " & rs("ccountry") & vbCrLf
            strBody = strBody & "Phone: " & rs("cphone") & vbCrLf
            strBody = strBody & "Email: " & rs("cemail") & vbCrLf & vbCrLf

          strBody = strBody & "Ordered items:" & vbCrLf
          strBody = strBody & "Product Code" & vbTab & vbTab & "|" &"Product Name" & vbTab & vbTab & "|"  & "Quantity." & vbTab & "|" & "Unit Price" & vbCrLf
          strBody = strBody & "-------------------------------------------------------" & vbCrLf
          dblOrderTotal = 0
          while not rs.EOF
               strBody = strBody & rs("ccode") & vbTab & "|" & rs("cname") & vbTab & "|"
               lineTotal = rs("cprice")*rs("numitems")
               strBody = strBody & rs("numitems") & vbTab & "|" & FormatCurrency(lineTotal,2) & vbCrLf
               dblOrderTotal = dblOrderTotal + lineTotal
               rs.MoveNext
          wend
          strBody = strBody & "-------------------------------------------------------" & vbCrLf
          strBody = strBody & "Total: " & FormatCurrency(dblOrderTotal,2) & vbCrLf
          strBody = strBody & vbCrLf & vbCrLf

            rs.Close
            set rs = nothing
            set cmd = nothing

      '*******************************************
      'code for sending email.  This will one work on windows 2000 or windows xp.
      Dim iMsg
      Set iMsg = CreateObject("CDO.Message")
      Dim iBp
      Dim Flds
      Dim iConf
      Set iConf = CreateObject("CDO.Configuration")
      Set Flds = iConf.Fields
      Flds(cdoSendUsingMethod)  = 2 'cdoSendUsingPort
      Flds(cdoSMTPServer)       = "mail.domain.com"
    Flds(cdoSendUsername) = "sales@domain.com"
    Flds(cdoSendPassword) = "sales"
      Flds(cdoSMTPServerPort)   = 25
      Flds(cdoSMTPAuthenticate)     = 1 'cdoAnonymous 0
      Flds.Update
      With iMsg
       Set .Configuration = iConf
           .From = "sales@domain.com"
           .To = "sales@domain.com; info@domain.com"
           .Subject     = "Health Products"
           .TextBody    = strBody
             .Send
      End With
            if Err.number > 0 then
                  mailMerchant = false
            else
                  mailMerchant = true
            end if

            else

            rs.Close
            set rs = nothing
            set cmd = nothing
            mailMerchant = false
      end if
      '************************************

end function
%>
0
Comment
Question by:nigerman
[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
  • 6
  • 3
9 Comments
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13444970
pad your strings right or left depending on the number of charachters allowed by you for each column.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>

<head>
<%
function padRight(string, length)
      Dim tmp, padding
      padding = "                                                    "
      tmp = string
      if Len(tmp) > length then
            tmp = Left(tmp, length)
      else ' Len(tmp) <= length
            tmp = Right((padding & tmp), length)
      end if
      padRight = tmp            
end function
%>
</head>

<body>
<pre>
12345678901234567890
<%=padRight("Rod", 15)%>
</pre>
</body>

</html>
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13445025
Oh and lose the tabs.

Most e-mail readers wrap the body at 76 characters, so you don't want to go over 76 per line.
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13445286
http://www.rodsdot.com/ee/padRight.asp

You'll probably want left and right pad functions since you have numbers.

0
7 Extremely Useful Linux Commands for Beginners

Just getting started with Linux? Here's a quick start guide that has 7 commands that we believe will come in handy.

 

Author Comment

by:nigerman
ID: 13446390
I saw your example, thanks but I am not sure how that is going to work in my case.

In fact I tried it but it didn't make any difference, unless of course I am using incorrectly
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13450799
Sure it will...

while not rs.EOF
               strBody = strBody & padLeft(rs("ccode"),22) & " | " & padLeft(rs("cname"),22) & " | "
               lineTotal = rs("cprice")*rs("numitems")
               strBody = strBody & padRight(rs("numitems"),12) & " | " & padRight(FormatCurrency(lineTotal,2),11) & vbCrLf
               dblOrderTotal = dblOrderTotal + lineTotal
               rs.MoveNext




---------------------------------------------------------------------------

function padRight(string, length)
      Dim tmp, padding
      padding = "                                                    "
      tmp = string
      if Len(tmp) > length then
            tmp = Left(tmp, length)
      else ' Len(tmp) <= length
            tmp = Right((padding & tmp), length)
      end if
      padRight = tmp            
end function

function padLeft(string, length)
      Dim tmp, padding
      padding = "                                                    "
      tmp = string
      if Len(tmp) > length then
            tmp = Left(tmp, length)
      else ' Len(tmp) <= length
            tmp = Left((tmp & padding), length)
      end if
      padLeft = tmp            
end function
0
 

Author Comment

by:nigerman
ID: 13451677
once again, let me thank you much for the continued assistance.

So far though, your code has not made any difference.

I wish there was a way to send the formatted output with your code and without your code... it is the same.

product code|product name|quantity|Unit Price

valuessdssd1| value1dsdffd|1|$2222.00
valuessdssdaaas2|value2dsdffd|1|$2222.00

I am getting something similar to above.

I know that if I run your code as you have it, it will probably work but I think the cdosys message is messing it up and that is where the problem lies.
         
0
 
LVL 29

Expert Comment

by:rdivilbiss
ID: 13547135
>I wish there was a way to send the formatted output with your code and without your code...

My e-mail is in my profile.
0
 
LVL 29

Accepted Solution

by:
rdivilbiss earned 500 total points
ID: 13561044
My code formats correctly for me, exactly as per your instructions.

You sure it isn't your e-mail client settings?  (e.g. Outlook and Outlook Express can be set to alter message display).

<%
function padRight(string, length)
      Dim tmp, padding
      padding = "                                                    "
      tmp = string
      if Len(tmp) > length then
            tmp = Left(tmp, length)
      else ' Len(tmp) <= length
            tmp = Right((padding & tmp), length)
      end if
      padRight = tmp            
end function

function padLeft(string, length)
      Dim tmp, padding
      padding = "                                                    "
      tmp = string
      if Len(tmp) > length then
            tmp = Left(tmp, length)
      else ' Len(tmp) <= length
            tmp = Left((tmp & padding), length)
      end if
      padLeft = tmp            
end function


Set objMessage = CreateObject("CDO.Message")
objMessage.Subject = "Example CDO Message"
objMessage.From = "...[snip]..."
objMessage.To = "...[snip]..."



'==This section provides the configuration information for the remote SMTP server.
'==Normally you will only change the server name or IP.

objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/sendusing") = 1

'Name or IP of Remote SMTP Server
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "localhost"

'Server port (typically 25)
objMessage.Configuration.Fields.Item _
("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 25

objMessage.Configuration.Fields.Update

'==End remote SMTP server configuration section==


Dim strBody
strBody = strBody & padLeft("valuessdssd1",22) & " | " & padLeft("value1dsdffd",22) &_
                   " | " & padRight("1",12) & " | " & padRight(FormatCurrency(999.99,2),11) & vbCrLf
strBody = strBody & padLeft("value",22) & " | " & padLeft("value",22) &_
                   " | " & padRight("22",12) & " | " & padRight(FormatCurrency(99999.99,2),11) & vbCrLf
strBody = strBody & padLeft("value3333",22) & " | " & padLeft("value333",22) &_
                   " | " & padRight("999",12) & " | " & padRight(FormatCurrency(2999.99,2),11) & vbCrLf
strBody = strBody & padLeft("value4040404",22) & " | " & padLeft("value4",22) &_
                   " | " & padRight("27",12) & " | " & padRight(FormatCurrency(29.99,2),11) & vbCrLf

objMessage.TextBody = strBody
objMessage.Send
%>

0
 

Author Comment

by:nigerman
ID: 13622238
I am truly sorry about this thread.

I had forgotten about it.

I had just seen your most current post, integrated it with my code and it works great.

I can't thank you well enough.

And sorry I had forgotten about this in the midst of the other pressing need.

Speaking of the other one, after reading this post, I saw that you didn't mind being sent an email.

I just sent you one, sorry about the inconvenience.

0

Featured Post

Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf

Question has a verified solution.

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

This article was originally published on Monitis Blog, you can check it here . Today it’s fairly well known that high-performing websites and applications bring in more visitors, higher SEO, and ultimately more sales. By the same token, downtime…
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Suggested Courses

801 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