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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Adding/mixing variables into Html code for Html Email

Status
Not open for further replies.

stanlyn

Programmer
Sep 3, 2003
945
US
Hi,

How would I compose a string that will be rendered as html as has variables and field values mixed in. Here is a sample of what I'm trying to do...

Code:
        * b0 = [<html><body><p>Greetings ] + gcUserName + "," + Chr(13) + CHR(10) + Chr(13) + CHR(10)
	b0 = "Greetings " + gcUserName + "," + Chr(13) + CHR(10) + Chr(13) + CHR(10)

	b1 = "You are receiving this email because you have a user account in " + gcCountyName + " county." + Chr(13) + CHR(10) + Chr(13) + CHR(10)

	b2 = "NEWS... We have finally gotten several ........ " + ;
		"data accessible online by their customers..... " + ;
		"to you to participate in an ........." + Chr(13) + CHR(10) + Chr(13) + CHR(10)

	b3 = "Imaging Live, is a rooms, complete with ............" + ;
		"full text, plat, source of page......., " + ;
		"faxing, and OCR text services...................." + Chr(13) + CHR(10) + Chr(13) + CHR(10)

	b4 = "Now, it's up To you, the cl............." + ;
		"brief survey to help us convey to other............." + ;
		" you will take part in........." + Chr(13) + CHR(10) + Chr(13) + CHR(10)

	*b5 = "Thanks!  You'll find the survey here..." + "[URL unfurl="true"]http://www.website.com"[/URL]
	b5 = [<html><body><p>Thanks!  You'll find the survey here... <a href="[URL unfurl="true"]http://www.wedsite.com">website.com</a></p></body></html>[/URL]]

	.edtBody.Value = b0 + b1 + b2 + b3 + b4 + b5

I'm currently storing the string into a vfp edit box to see the output. Then I pass the value of the editbox to the ChilKat smpt control like this: loEmail.SetHtmlBody(Alltrim(.edtBody.Value))

The ChilKat example line is: loEmail.SetHtmlBody([<html><body><p>This is <b>bold text</b>, this is a <a href="])

The problem is it doesn'y factor in variables and field names within it...

This is my first attempt at writing html, and there is tons of help for that, but google yields little help mixing vfp values and html...

And I actually have Rick's book "Internet Applications with VFP6" and I don't see anything of help there.

Also, would using vfp's TEXT ... ENDTEXT Command be useful for this instead of concatenating several variables as I've done to get past the 256 char limit? And yes, I know the textbox is what has the 256 char limit, whereas the editbox does not, Its just as I started this using a textbox and all the multiple variables was already done...

Thanks,
Stanley
 
Hi Stanley,

the way you got it is already working, isn't it? You do incorporate gcCountyName in your text. So far all you're missing is a html skeleton and some html knowledge to put a text in some paragraphs. I just don't see anything, that would really benefit from HTML, why not use a plaintext mail for this kind of text, if html is beyond you?

And yes, a TEXT..ENDTEXT section will remove severeal double quotes, and CHR() calls, as you simply put the tet in some lines. Even more helpful is using the TEXTMERGE option and putting in variables or expressions with <<variable>>.

What you're not getting from a html body without some basic html knowledge is linefeeds or paragraphs, just because you have them in the TEXT..ENDTEXT section. So the minimum html tags to know are <p> and <br>. For the overall skeleton <html> and <body>, but not for such simple texts, simply use plaintext, unless you plan to brush up the mail look, but that'll need more html knowledge.

You don't need the sethtmlbody, you can also settextbody. Is theree any reason you bought chillkats smtp control?
Sending mails is something you don't need any third party component for. Search in the faq section, Craig S. Boyds blog or in the Fox Wiki and you find tons of samples.

Bye, Olaf.
 
You should definitely go with TEXT/ENDTEXT. It is much esier than concatenating several variables, and the results are more readable. I'd advice temporarily disabling Intellisense while you are typing the text into your program, otherwise you might get unwanted capitalisation and word completion.

Consider also using SET TEXTMERGE DELIMITERS to change the delimiters within the TEXT/ENDTEXT. The default delimiters are double angle brackets (<< and >>), which are very similar to the HTML delimiters (< and >). Although this probably won't cause a problem, it might be a little confusing when you are reviewing the text.

Regarding the preview of the text. You can do this in an edit box, as you suggested, but this will show the text with the embedded HTML tags, rather than the formatted text. That might be good enough, but if you want a proper preview just as it will eventually look in the email message, you could use the Web Browser ActiveX control that comes with VFP.

Finally, if you are not sure which HTML tags to use, consider downloading an HTML WYSIWYG editing tool. There are several available. It will let you enter and format the text like you do in a word processor, and then generate the HTML, which you can then paste into your program.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Olaf,

No it doesn't work. It works fine if I send it as a plain text email complete with paragraphs. The problem was the hyperlink not being clickable in the emails body, therefore I started working on the html version.

I'm going to have to learn the html stuff anyway and figured this as good a place as any to learn.

I purchased a complete ChilKat library mainly for its cryptology functions and smtp was in there and it was simple to implement, so why not... So far after processing some 6 million encryption and decryption processes, I have had 0 failures on ChilKat's behalf. For the first time last night, I started using the smpt functions and after about 10 emails, I have had 0 failures. I believe sethtmlbody is a ChilKat function, because it is the only line that is different between smpt plain text and html examples. Years ago I provided this same functionality using blat. ChilKat is much simpler to implement...

Are you thinking something like this should work...
Code:
SET TEXTMERGE OFF
TEXT to myvar noshow
     [<html><body><p>Greetings ] <<gcUserName>> [,]</p>
     <p>[You are receiving this email because you have a user account in ] <<gcCountyName>> [ county.]</p>
     <p>[NEWS... We have finally gotten several ........ data accessible online by their customers..... to you to participate in]</p> 
     <p>[Imaging Live, is a rooms, complete with .... full text, plat, source of page... faxing, and OCR text services...]</p>  
     <p>[Now, it's up To you, the cl rief survey to help us convey to other...... you will take part in.....]</p>
     <p>[Thanks!  You'll find the survey here... <a> href="[URL unfurl="true"]http://www.wedsite.com">website.com</a></p></body></html>[/URL]]
endtext

Thanks,
Stanley
 
Hi Mike,

Mike said:
Finally, if you are not sure which HTML tags to use, consider downloading an HTML WYSIWYG editing tool. There are several available. It will let you enter and format the text like you do in a word processor, and then generate the HTML, which you can then paste into your program.

I've already tried that, but that doesn't help with the mixing of vfp variables and external data from fields and functions... Thats why I'm posting here where all the vfp gurus hangout, just hoping for a vfp guru that is also a html guru...

Thanks,
Stanley
 
that doesn't help with the mixing of vfp variables and external data from fields and functions.

But it looks like you already know how to do that. You have inserted [tt]<<gcCountyName>>[/tt] and [tt]<<gcUserName>>[/tt] into your HTML. The TEXT/ENDTEXT construct will automatically expand that to the correct user and county names. You can do the same with any VFP function or expression. For example, [tt]<<DATE()>>[/tt] will expand to today's date.

But to make that work, you need to issue SET TEXTMERGE ON. You have got it set OFF.

I'm not sure why you've got square brackets at the start and end of each line. That looks like hangover from when you were concatenating separate variables.

Mike


__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Hi Mike,

Setting textmerge to on and removing all the [ and ] has it working as expected, however I need to hide the href=" and "> in this last line. This line is exactly as shown in the html email...

Thanks! You'll find the survey here... href="
I would like it to be:
Thanks! You'll find the survey here...
Thanks,
Stanley
 
Second:

[tt]SET TEXTMERGE OFF[/tt]

You neither set textmerge on nor off, you ue the TEXTMERGE [highlight #FCE94F]option[/highlight] of the TEXRT TO command:

[tt]TEXT TO myvar NOSHOW TEXTMERGE
...your html mail...including <<gcCountyName>>...
ENDTEXT
[/tt]

Bye, Olaf.
 
OK,

All fixed now... by changing <a> href=" to <a href="

Thanks Olaf and Mike,

I'm sure I be back for more html stuff.

Stanley
 
>back for more html stuff.

Well, there are html forums here, too: forum215

Also it's really a separate topic and if you separate the html part from your vfp code the html experts will help you, too.
Now that you can separate the html from the rest of the vfp code and can later put in the <<placeholders>> you can get much more and better answers there. I'm also there sometimes.

Bye, Olaf.
 
Code:
TEXT TO myvar NOSHOW TEXTMERGE
     [<html><body><p>Greetings ] <<gcUserName>> [,]</p>
     <p>[You are receiving this email because you have a user account in ] <<gcCountyName>> [ county.]</p>
     <p>[NEWS... We have finally gotten several ........ data accessible online by their customers..... to you to participate in]</p> 
     <p>[Imaging Live, is a rooms, complete with .... full text, plat, source of page... faxing, and OCR text services...]</p>  
     <p>[Now, it's up To you, the cl rief survey to help us convey to other...... you will take part in.....]</p>
     <p>[Thanks!  You'll find the survey here... <a> href="[URL unfurl="true"]http://www.wedsite.com">website.com</a></p></body></html>[/URL]]
endtext

Remove all the square brackets in there, at least the outer ones html starts with <html> and ends with </html> (apart of an optional doctype and some other things) but square brackets don't go there, the whole thing already is a string from TEXT TO myvar, no need for any string delimiters, unless you want the square brackets inside the paragraphs.

Bye, Olaf.
 
[pre]TEXT to myvar noshow textmerge
<html><body><p>Greetings <<gcUserName>>,</p>
<p>You are receiving this email because you have a user account in <<gcCountyName>> county.</p>
<p>NEWS... We have finally gotten several ........ data accessible online by their customers..... to you to participate in</p>
<p>Imaging Live, is a rooms, complete with .... full text, plat, source of page... faxing, and OCR text services...</p>
<p>Now, it's up To you, the cl rief survey to help us convey to other...... you will take part in.....</p>
<p>Thanks! You'll find the survey here... <a href="endtext[/pre]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top