Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with CDONTS and Quotation Marks

Status
Not open for further replies.

Rexolio

Technical User
Aug 29, 2001
230
0
0
I have a script I use on one of my sites that allows registered members to email the other registered members. The enter their email address, subject and message and then submits it to a page that goes through the database, record by record, and sends each member their own individual copy.

The problem I'm having, and I've posted this before with a resolution, is that sometimes a member will enter quotation marks in the body of their message, I guess to emphasize something here or there. Anyway, when this happens, it cuts off the email message from the point where the quotation mark was entered, so people get incomplete messages. I've tried several ways to fix this, but still haven't resolved it. I've had to put up a message telling the user not to use quotation marks, which I don't like having to do, and people still do it anyway.

Looking for some help! Here's the original code I'm using:

<%
strEmail = Request.form(&quot;SendersEmail&quot;)
strSubj = Request.form(&quot;Subject&quot;)
strMsg = Request.form(&quot;Message&quot;)


SQL=&quot;SELECT * FROM Members ORDER BY MemberLN, MemberFN&quot;
set List=Conn.execute(SQL)
do while not List.eof

if List(&quot;Email&quot;) <> &quot;&quot; then
strName = List(&quot;MemberFN&quot;) & &quot; &quot; & List(&quot;MemberLN&quot;)

Dim myMail
Set myMail = Server.CreateObject(&quot;CDONTS.NewMail&quot;)
myMail.Send strEmail, List(&quot;Email&quot;), strSubj, strName & &quot;,&quot; & vbcrlf & vbcrlf & strMsg & vbcrlf & vbcrlf & &quot;NOTE:&quot; & vbcrlf & &quot;You are receiving this email as a Subscribed member. To Unsubscribe from this list, click here: & List(&quot;MemberID&quot;)
Set myMail = Nothing

end if

List.movenext
loop
List.close
%>

Thanks in Advance,
Rexolio
 
Hoping someone can help with this!
 
Surely someone out there knows how to handle this? [sadeyes]
 
I'd probably just replace any &quot; with chr(34)

dim theVar
theVar = request.form(&quot;theVar&quot;)
theVar = replace(theVar,&quot;&quot;&quot;&quot;,&quot;chr(34)&quot;)

and see if that clears it up.

penny1.gif
penny1.gif
 
thanks, line9. however, unfortunately I've tried that before but it didn't fix it. got any more suggestions?
 
Have you tried using HTMLEncode on the the subject and message fields
 
no I haven't...how would that work?
 
On second thought's scratch that idea... try the following code

Add

Dim msgBody as String to declarations

Dim myMail
Set myMail = Server.CreateObject(&quot;CDONTS.NewMail&quot;)
myMail.From = strEmail
myMail.To = List(&quot;Email&quot;)
myMail.Subject = strSubj

msgBody = strName & &quot;,&quot; & vbcrlf & vbcrlf & strMsg & vbcrlf & vbcrlf & &quot;NOTE:&quot; & vbcrlf & &quot;You are receiving this email as a Subscribed member. To Unsubscribe from this list, click here: & List(&quot;MemberID&quot;)

myMail.Body = msgBody

myMail.send
Set myMail = Nothing
 
I've used that before, and I guess I could try it here. But not sure how this would fix the situation. I'll give it a try...

other suggestions?
 
Have you tried replacing all the quotes to PAIRS of quotes. I may be mixing up vb and html, but I think html will recognize a pair of quotes as &quot;embedded&quot; within the outer quotes and won't terminate your string. You will have to do this on the CLIENT side, before submitting the form. I.e., in your FORM tag add OnSubmit=fnSubmitForm, and in the fnSubmitForm function do the Replace and submit the form. If that doesn't work, then just convert them to spaces or empty strings. Either way, the key is doing it on the client side before the form is submitted. Let me know if you need code samples.
 
sakilgor...code samples would be GREAT!!! Thanks so much!
 
OK, I didn't read your problem carefully, sorry. Ignore all my stuff about fixing on the client side! Your problem is when you are calling the cdo Send method. I think LINK9's suggestion was on the right track, but you need to replace the quotes with SOMETHING ELSE. Either strip them out (code #1 below), or, if cdo will treat a PAIR of quotes as embedded, use #2. I wasn't sure if you were talking about double or single quotes. #3 and #4 do the same thing with single quotes. I just tested all four of these, and they work as advertised. Good luck!

(1) strMsg = Replace(Request.form(&quot;Message&quot;),&quot;&quot;&quot;&quot;,&quot;&quot;)
(2) strMsg = Replace(Request.form(&quot;Message&quot;),&quot;&quot;&quot;&quot;,&quot;&quot;&quot;&quot;&quot;&quot;)
(3) strMsg = Replace(Request.form(&quot;Message&quot;),&quot;'&quot;,&quot;&quot;)
(4) strMsg = Replace(Request.form(&quot;Message&quot;),&quot;'&quot;,&quot;''&quot;)
 
sakligor,

I have tried the first to methods before, which didn't work. But to make absolutely sure since it had been a while, I tried again. Same results - email gets cut off at the point where the first quotation mark comes into play.
 
Even tried changing around the script as Xenobia suggested even though mine was the same thing, only sloppier...still the same result!!! PLEAAASSEEE...any more suggestions, folks?
 
I think it has to be at the end of this line:
& &quot;You are receiving this email as a Subscribed member. To Unsubscribe from this list, click here: & List(&quot;MemberID&quot;)

Notice you have:
&quot;; & List(&quot;MemberID&quot;)
That semi-colon is out of place I think.
 
Its not there in my page...I change the address to keep my site off of the posting and I guess it got put there when I edited it after pasting it here. But its not there.
 
You know what... your right. Cause when I look at my post it added another one.
 
Are you sure the string is making it intact from the sending form? In other words, if you put in a response.write at the beginning of the receiving asp,
Response.write Request.form(&quot;Message&quot;)
do you do see the entire string there, not cut off?
'Cause if you do, and you strip out all single and double quotes from that string, (maybe put in another response.write right before you call cdo to verify the string is indeed quote-clean!), then send it to CDO, I don't see how CDO could possibly know where a quote WAS BEFORE and be chopping your string at that point?!!

You might want to put in one more response.write at the end to display the entire string, with all the concatenations and literals, exactly as you are sending them to cdo to be sure you are sending what you think you are.

This one's a bugger! Good luck!
 
Look, I know it may be a little crap, but why don't you replace the double quotes with something else? Perhaps single quotes as they don't seem to be rocking the boat, or you could go radical and even change it to another character such as an asterisk (or two), tilde or even an underscore (oooh).

Users do tend to except this ~change~ in typesetting etiquette for the sake of *ease of use* and a small note to them along the lines of _double quote marks will be changed to underscores_ will help them through the **trauma** of having to live with this change. Derren
[The only person in the world to like Word]
 
Okay, ITS FIXED FINALLY AFTER 6 MONTHS OF TRYING.

Most of the suggestions that you guys made I have tried at one point, and then again when you made them. Unfortunately it never worked. Is there such a thing as getting so wrapped up in &quot;why doesn't this work?&quot; that you fail to find other solutions that would save yourself time and possibly make a better program?

Maybe I was still doing something wrong, but the sample code I listed above WITH the suggestions you guys made wouldn't work. Not sure why. Even
Code:
Replace(strMsg,&quot;&quot;&quot;&quot;,&quot;&quot;)
didn't work. HOWEVER, and maybe someone can tell me what it didn't work, but I decided to insert a page between the page where the Email content is entered by the user and the page that actually sends out the email to the database members and confirms it for the sender. It basically displays the email as it will look for the recipient and gives the sender one more chance to either go back and edit or to go ahead and send. On this page I included a form with all of the info in hidden input fields. I took the Message and tried once again to replace quotes with a nothing
Code:
Replace(strMsg,&quot;&quot;&quot;&quot;,&quot;&quot;)[code][/b] and then submit it to the next page that sends the email out. It worked like a charm. 

After all that time. Maybe its going around my kneecap to get to my elbow, but it works. I'm still puzzled as to why this wouldn't work in the cdo...why this interered with the message.

I'm sorry if I've wasted everyone's time. But I appreciate it. It made me take another look at it and find a better way...or at least a way that worked.

Thanks!
Rexolio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top