Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Email formatting

Posted on 2005-03-02
9
Medium Priority
?
282 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
  • 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
By following these Magento e-commerce development tips, you can increase your website's conversion and profitability. Read this post for more details.
The viewer will learn how to dynamically set the form action using jQuery.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month11 days, 21 hours left to enroll

564 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