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

ASP to E-mail as HTML

Status
Not open for further replies.

Leeus

Programmer
Sep 10, 2001
40
GB
Here is the ASP code I have:
<%@LANGUAGE=&quot;VBSCRIPT&quot;%>
<!--#include file=&quot;Connections/highmightynews.asp&quot; -->
<%
Dim news__weekn
news__weekn = &quot;2&quot;
if (request.querystring(&quot;Week&quot;) <> &quot;&quot;) then news__weekn = request.querystring(&quot;Week&quot;)
%>
<%
set news = Server.CreateObject(&quot;ADODB.Recordset&quot;)
news.ActiveConnection = MM_highmightynews_STRING
news.Source = &quot;SELECT * FROM Main WHERE Week=&quot; + Replace(news__weekn, &quot;'&quot;, &quot;''&quot;) + &quot; and category = '1'&quot;
news.CursorType = 0
news.CursorLocation = 2
news.LockType = 3
news.Open()
news_numRows = 0
%>
<%
Dim offers__weekn
offers__weekn = &quot;1&quot;
if (request.querystring(&quot;Week&quot;) <> &quot;&quot;) then offers__weekn = request.querystring(&quot;Week&quot;)
%>
<%
set offers = Server.CreateObject(&quot;ADODB.Recordset&quot;)
offers.ActiveConnection = MM_highmightynews_STRING
offers.Source = &quot;SELECT * FROM Main WHERE Week=&quot; + Replace(offers__weekn, &quot;'&quot;, &quot;''&quot;) + &quot; and category = '2'&quot;
offers.CursorType = 0
offers.CursorLocation = 2
offers.LockType = 3
offers.Open()
offers_numRows = 0
%>
<%
Dim cat3__weekn
cat3__weekn = &quot;1&quot;
if (request.querystring(&quot;Week&quot;) <> &quot;&quot;) then cat3__weekn = request.querystring(&quot;Week&quot;)
%>
<%
set cat3 = Server.CreateObject(&quot;ADODB.Recordset&quot;)
cat3.ActiveConnection = MM_highmightynews_STRING
cat3.Source = &quot;SELECT * FROM Main WHERE Week=&quot; + Replace(cat3__weekn, &quot;'&quot;, &quot;''&quot;) + &quot; and category = '3'&quot;
cat3.CursorType = 0
cat3.CursorLocation = 2
cat3.LockType = 3
cat3.Open()
cat3_numRows = 0
%>
<%
Dim cat4__weekn
cat4__weekn = &quot;1&quot;
if (request.querystring(&quot;Week&quot;) <> &quot;&quot;) then cat4__weekn = request.querystring(&quot;Week&quot;)
%>
<%
set cat4 = Server.CreateObject(&quot;ADODB.Recordset&quot;)
cat4.ActiveConnection = MM_highmightynews_STRING
cat4.Source = &quot;SELECT * FROM Main WHERE Week=&quot; + Replace(cat4__weekn, &quot;'&quot;, &quot;''&quot;) + &quot; and category = '4'&quot;
cat4.CursorType = 0
cat4.CursorLocation = 2
cat4.LockType = 3
cat4.Open()
cat4_numRows = 0
%>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
<style type=&quot;text/css&quot;>
<!--
a { font-family: Verdana; font-size: 12px; color: #000000}
p { font-family: Verdana; font-size: 12px; color: #000000}
-->
</style>
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!-- Begin
function viewSource() {
document.getSource.view.value=&quot;Please wait!&quot;;
setTimeout(&quot;document.getSource.view.value='View Source!'&quot;,6000);
window.location.href= &quot;view-source:&quot; + document.location.url.value;
return false;
}

function openbrochure(windowurl) {
brochurewindow = window.open(windowurl, &quot;brochurewindow&quot; ,&quot;scrollbars=no,resizable=no,status=no,toolbar=no,menubar=no,location=no,directories=no,width=550,height=290&quot;);
brochurewindow.focus();
}

function openterms(windowurl) {
termswindow = window.open(windowurl, &quot;termswindow&quot; ,&quot;scrollbars=no,resizable=no,status=no,toolbar=no,menubar=no,location=no,directories=no,width=350,height=276&quot;);
termswindow.focus();
}

function Opensizing(windowurl) {
sizingwindow = window.open(windowurl, &quot;sizingwindow&quot; ,&quot;scrollbars=no,resizable=no,status=no,toolbar=no,menubar=no,location=no,directories=no,width=400,height=410&quot;);
sizingwindow.focus();
}
function Opencontact(windowurl) {
contact = window.open(windowurl,&quot;contact&quot;,&quot;scrollbars=no,resizable=no,status=no,toolbar=no,menubar=no,location=no,directories=no,width=550,height=400&quot;);
contact.focus();
}
function MM_findObj(n, d) { //v4.0
var p,i,x; if(!d) d=document; if((p=n.indexOf(&quot;?&quot;))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers.document);
if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_validateForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args);
if (val) { nm=val.name; if ((val=val.value)!=&quot;&quot;) {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') {
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
// End -->
</script>
</head>
<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<table width=&quot;800&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; align=&quot;center&quot;>
<tr>
<td height=&quot;545&quot; valign=&quot;top&quot;>
<table width=&quot;84%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td><img src=&quot; width=&quot;800&quot; height=&quot;60&quot;></td>
</tr>
</table>
<table width=&quot;800&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; height=&quot;324&quot;>
<tr>
<td bgcolor=&quot;#DACFCB&quot; width=&quot;100&quot; valign=&quot;top&quot; height=&quot;252&quot;>
<p align=&quot;center&quot;><br>
Issue
<% If Not news.EOF Or Not news.BOF Then %>
<%=(news.Fields.Item(&quot;Week&quot;).Value)%>
<% End If ' end Not offers.EOF Or NOT offers.BOF %>
<br>
<% If news.EOF And news.BOF Then %>
No Issue to display
<% End If ' end offers.EOF And offers.BOF %>
</p>
<table width=&quot;99%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;4&quot;>
<tr>
<td width=&quot;100%&quot;>
<p><a href=&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Special
Offer</font></a></p>
<p><font face=&quot;Arial, Helvetica, sans-serif&quot;><a href=&quot; <p><font face=&quot;Arial, Helvetica, sans-serif&quot;><a href=&quot; Us</a></font></p>
</td>
</tr>
</table>
</td>
<td height=&quot;252&quot; valign=&quot;top&quot;>
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td bgcolor=&quot;#DACFCB&quot;><font color=&quot;#003399&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>
</font></td>
</tr>
</table>
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td>
<p> </p>
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;5&quot; height=&quot;77&quot;>
<tr>
<td width=&quot;217&quot; valign=&quot;top&quot;>
<% If news.EOF And news.BOF Then %>
<p>Please make sure you have entered a value for category
1</p>
<% End If ' end news.EOF And news.BOF %>
<% If Not news.EOF Or Not news.BOF Then %>
<p><%=(news.Fields.Item(&quot;Title&quot;).Value)%></p>
<p><%=(news.Fields.Item(&quot;Content&quot;).Value)%></p>
<% End If ' end Not news.EOF Or NOT news.BOF %>
</td>
<td width=&quot;217&quot; valign=&quot;top&quot;>
<% If offers.EOF And offers.BOF Then %>
<p>Please make sure you have entered a value for category
2</p>
<% End If ' end offers.EOF And offers.BOF %>
<% If Not offers.EOF Or Not offers.BOF Then %>
<p><%=(offers.Fields.Item(&quot;Title&quot;).Value)%></p>
<p><%=(offers.Fields.Item(&quot;Content&quot;).Value)%></p>
<% End If ' end Not offers.EOF Or NOT offers.BOF %>
</td>
</tr>
</table>
<div align=&quot;left&quot;></div>
<table width=&quot;100%
&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;5&quot; height=&quot;77&quot; align=&quot;left&quot;>
<tr>
<td width=&quot;150&quot; valign=&quot;top&quot;>
<% If cat3.EOF And cat3.BOF Then %>
<p>Please make sure you have entered a value for category
3</p>
<% End If ' end cat3.EOF And cat3.BOF %>
<% If Not cat3.EOF Or Not cat3.BOF Then %>
<p><%=(cat3.Fields.Item(&quot;Title&quot;).Value)%></p>
<p> <%=(cat3.Fields.Item(&quot;Content&quot;).Value)%></p>
<% End If ' end Not cat3.EOF Or NOT cat3.BOF %>
</td>
<td width=&quot;150&quot; valign=&quot;top&quot;>
<% If cat4.EOF And cat4.BOF Then %>
<p>Please make sure you have entered a value for category
4</p>
<% End If ' end cat4.EOF And cat4.BOF %>
<% If Not cat4.EOF Or Not cat4.BOF Then %>
<p><%=(cat4.Fields.Item(&quot;Title&quot;).Value)%></p>
<p><%=(cat4.Fields.Item(&quot;Content&quot;).Value)%></p>
<% End If ' end Not cat4.EOF Or NOT cat4.BOF %>
</td>
</tr>
</table>
<p> </p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width=&quot;99%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;4&quot;>
<tr>
<td width=&quot;151&quot; valign=&quot;middle&quot;><a href=&quot; target=-&quot;_blank&quot;><img src=&quot; width=&quot;41&quot; height=&quot;50&quot; border=&quot;0&quot;></a>  <a href=&quot; target=&quot;_blank&quot;><img src=&quot; width=&quot;80&quot; height=&quot;50&quot; border=&quot;0&quot;></a></td>
<td align=&quot;center&quot; width=&quot;690&quot;><font face=&quot;garamond&quot; color=&quot;#0E1F87&quot; size=&quot;-1&quot;><a href=&quot;javascript:eek:penbrochure(' Brochure</a> - <a href=&quot;javascript:eek:penterms(' and Conditions</a> - <a href=&quot;javascript:Opensizing(' Sizing</a> - <a href=&quot; target=&quot;main&quot;>About
Us</a> - <a href=&quot; target=&quot;main&quot;>Where
are we?</a> - <a href=&quot;javascript:Opencontact(' Us</a></font></td>
<td align=&quot;center&quot; width=&quot;65&quot; valign=&quot;bottom&quot;><img src=&quot; width=&quot;187&quot; height=&quot;25&quot; align=&quot;bottom&quot;></td>
<td width=&quot;71&quot; align=&quot;center&quot;>
<div align=&quot;right&quot;>
<table border='0' cellspacing='0' cellpadding='0'>
<tr>
<td align='center'><a href=' target=&quot;_blank&quot;><img src=' border='0'></a></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<p>
</td>
</tr>
</table>
<p> </p>
</body>
</html>
<%
news.Close()
%>
<%
offers.Close()
%>
<%
cat3.Close()
%>
<%
cat4.Close()
%>


Just a quick uestion, how do I convert the actual DB extracted values to HTML to send as an e-mail.
 
ues CDONTS and build the entire page html as a string

strBody = &quot;<body bgcolor=&quot;#FFFFFF&quot; text=&quot;#000000&quot;>
<table width=&quot;800&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; align=&quot;center&quot;>
<tr>
<td height=&quot;545&quot; valign=&quot;top&quot;>
<table width=&quot;84%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td><img src=&quot; width=&quot;800&quot; height=&quot;60&quot;></td>
</tr>
</table>
<table width=&quot;800&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; height=&quot;324&quot;>
<tr>
<td bgcolor=&quot;#DACFCB&quot; width=&quot;100&quot; valign=&quot;top&quot; height=&quot;252&quot;>
<p align=&quot;center&quot;><br>
Issue
<% If Not news.EOF Or Not news.BOF Then %>
<%=(news.Fields.Item(&quot;Week&quot;).Value)%>
<% End If ' end Not offers.EOF Or NOT offers.BOF %>
<br>
<% If news.EOF And news.BOF Then %>
No Issue to display
<% End If ' end offers.EOF And offers.BOF %>
</p>
<table width=&quot;99%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;4&quot;>
<tr>
<td width=&quot;100%&quot;>
<p><a href=&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>Special
Offer</font></a></p>
<p><font face=&quot;Arial, Helvetica, sans-serif&quot;><a href=&quot; <p><font face=&quot;Arial, Helvetica, sans-serif&quot;><a href=&quot; Us</a></font></p>
</td>
</tr>
</table>
</td>
<td height=&quot;252&quot; valign=&quot;top&quot;>
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td bgcolor=&quot;#DACFCB&quot;><font color=&quot;#003399&quot; face=&quot;Arial, Helvetica, sans-serif&quot;>
</font></td>
</tr>
</table>
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<tr>
<td>
<p> </p>
<table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;5&quot; height=&quot;77&quot;>
<tr>
<td width=&quot;217&quot; valign=&quot;top&quot;>
<% If news.EOF And news.BOF Then %>
<p>Please make sure you have entered a value for category
1</p>
<% End If ' end news.EOF And news.BOF %>
<% If Not news.EOF Or Not news.BOF Then %>
<p><%=(news.Fields.Item(&quot;Title&quot;).Value)%></p>
<p><%=(news.Fields.Item(&quot;Content&quot;).Value)%></p>
<% End If ' end Not news.EOF Or NOT news.BOF %>
</td>
<td width=&quot;217&quot; valign=&quot;top&quot;>
<% If offers.EOF And offers.BOF Then %>
<p>Please make sure you have entered a value for category
2</p>
<% End If ' end offers.EOF And offers.BOF %>
<% If Not offers.EOF Or Not offers.BOF Then %>
<p><%=(offers.Fields.Item(&quot;Title&quot;).Value)%></p>
<p><%=(offers.Fields.Item(&quot;Content&quot;).Value)%></p>
<% End If ' end Not offers.EOF Or NOT offers.BOF %>
</td>
</tr>
</table>
<div align=&quot;left&quot;></div>
<table width=&quot;100%
&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;5&quot; height=&quot;77&quot; align=&quot;left&quot;>
<tr>
<td width=&quot;150&quot; valign=&quot;top&quot;>
<% If cat3.EOF And cat3.BOF Then %>
<p>Please make sure you have entered a value for category
3</p>
<% End If ' end cat3.EOF And cat3.BOF %>
<% If Not cat3.EOF Or Not cat3.BOF Then %>
<p><%=(cat3.Fields.Item(&quot;Title&quot;).Value)%></p>
<p> <%=(cat3.Fields.Item(&quot;Content&quot;).Value)%></p>
<% End If ' end Not cat3.EOF Or NOT cat3.BOF %>
</td>
<td width=&quot;150&quot; valign=&quot;top&quot;>
<% If cat4.EOF And cat4.BOF Then %>
<p>Please make sure you have entered a value for category
4</p>
<% End If ' end cat4.EOF And cat4.BOF %>
<% If Not cat4.EOF Or Not cat4.BOF Then %>
<p><%=(cat4.Fields.Item(&quot;Title&quot;).Value)%></p>
<p><%=(cat4.Fields.Item(&quot;Content&quot;).Value)%></p>
<% End If ' end Not cat4.EOF Or NOT cat4.BOF %>
</td>
</tr>
</table>
<p> </p>
</td>
</tr>
</table>
</td>
</tr>
</table>
<table width=&quot;99%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;4&quot;>
<tr>
<td width=&quot;151&quot; valign=&quot;middle&quot;><a href=&quot; target=-&quot;_blank&quot;><img src=&quot; width=&quot;41&quot; height=&quot;50&quot; border=&quot;0&quot;></a> <a href=&quot; target=&quot;_blank&quot;><img src=&quot; width=&quot;80&quot; height=&quot;50&quot; border=&quot;0&quot;></a></td>
<td align=&quot;center&quot; width=&quot;690&quot;><font face=&quot;garamond&quot; color=&quot;#0E1F87&quot; size=&quot;-1&quot;><a href=&quot;javascript:eek:penbrochure(' Brochure</a> - <a href=&quot;javascript:eek:penterms(' and Conditions</a> - <a href=&quot;javascript:Opensizing(' Sizing</a> - <a href=&quot; target=&quot;main&quot;>About
Us</a> - <a href=&quot; target=&quot;main&quot;>Where
are we?</a> - <a href=&quot;javascript:Opencontact(' Us</a></font></td>
<td align=&quot;center&quot; width=&quot;65&quot; valign=&quot;bottom&quot;><img src=&quot; width=&quot;187&quot; height=&quot;25&quot; align=&quot;bottom&quot;></td>
<td width=&quot;71&quot; align=&quot;center&quot;>
<div align=&quot;right&quot;>
<table border='0' cellspacing='0' cellpadding='0'>
<tr>
<td align='center'><a href=' target=&quot;_blank&quot;><img src=' border='0'></a></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
<p>
</td>
</tr>
</table>
<p> </p>
</body>
</html>
&quot;

.body = strBody

then just send the email

hth
Bastien

There are many ways to skin this cat,
but it still tastes like chicken
 
Sorry what did you mean by CDONTS?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top