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

Web form only sometimes sends an email

Status
Not open for further replies.

frainbreeze

Technical User
Jul 31, 2003
123
0
0
GB
hello,

i am new to asp so please bear with me! this is the script we are using for any comments/enquiries to be sent as an email to us via our website. even if there are no changes to the actual code, whether or not an email is actually sent seems to be completely random..i.e. it'll work one minute and the next it won't. can anyone please figure out where things are going wrong? i don't understand why it is being so temperamental..

this is in the head:
Code:
<script language=&quot;JavaScript&quot;>
function MM_findObj(n, d) { //v4.01
  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[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.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[i]);
    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 == '');
}
</script>

this is in the body:
Code:
<%
Dim objCDO  ' Our CDO object
Dim strTo   ' Strings to hold our email fields from the form
Dim strSubject
Dim strBody
Dim strnum
Dim reciever_email

strTo =  &quot;my@emailaddress.com&quot;

str_fullName = Request.form(&quot;name&quot;)
str_CompanyName = Request.form(&quot;company&quot;)
str_EmailAddress = Request.form(&quot;emailFrom&quot;)
str_message = Request.form(&quot;emailMessage&quot;)

strSubject = &quot;Message from the website&quot;

strBody = &quot;<!DOCTYPE HTML PUBLIC &quot;&quot;-//W3C//DTD HTML 4.0 Transitional//EN&quot;&quot;>&quot; & vbCrLf _
		& &quot;<html>&quot; & vbCrLf _
		& &quot;<head>&quot; & vbCrLf _
		& &quot; <title>Message from Livegroup website</title>&quot; & vbCrLf _
		& &quot; <meta http-equiv=Content-Type content=&quot;&quot;text/html; charset=iso-8859-1&quot;&quot;>&quot; & vbCrLf _
		& &quot;</head>&quot; & vbCrLf _
		& &quot;<body bgcolor='#FFFFFF' style='font-family: ariel, sans-serif'>&quot; & vbCrLf _
		& &quot; <h2>Message from Livegroup website</h2>&quot; & vbCrLf _
		& &quot; <p>&quot; & vbCrLf _
		& &quot; </p>&quot; & vbCrLf _
		& &quot; <font size='3'>&quot; & vbCrLf _
		& &quot;  <p>Name: &quot; & str_fullName & &quot;</p>&quot; & vbCrLf _
 		& &quot;  <p>Company: &quot; & str_CompanyName & &quot;</p>&quot; & vbCrLf _
 		& &quot;  <p>Message: &quot; & str_message & &quot;</p>&quot; & vbCrLf _
		& &quot; </font>&quot; & vbCrLf _
		& &quot;</body>&quot; & vbCrLf _
		& &quot;</html>&quot; & vbCrLf

If ( NOT Request.form( &quot;Submit&quot; )= &quot;Send&quot; ) THEN
%>
<table>
 <tr>
  <td height=&quot;130&quot; valign=&quot;bottom&quot;><font size=&quot;2&quot;>Please feel free to contact us using the form below: <br></font></td>
 </tr>
 <tr>
<form action=&quot;contact.asp&quot; name=&quot;form1&quot; method=&quot;POST&quot;>
 <table>
  <tr>
   <td><font style=&quot;font-weight: bold&quot;>Name</font>
   </td>
   <td><input name=&quot;name&quot; type=&quot;text&quot; maxlength=&quot;50&quot; style=&quot;width: 150px&quot;>
   </td>
  </tr>
  <tr>
   <td><font style=&quot;font-weight: bold&quot;>Company</font>
   </td>
   <td><input name=&quot;company&quot; type=&quot;text&quot; maxlength=&quot;150&quot; style=&quot;width: 150px&quot;>
   </td>
  </tr>
  <tr>
   <td><font style=&quot;font-weight: bold&quot;>Email</font>
   </td>
   <td><input name=&quot;emailFrom&quot; type=&quot;text&quot; maxlength=&quot;50&quot; style=&quot;width: 150px&quot;>
   </td>
  </tr>
  <tr>
   <td><font style=&quot;font-weight: bold&quot;>Enquiry</font>
   </td>
   <td><textarea name=&quot;emailMessage&quot; rows=&quot;5&quot; wrap=&quot;virtual&quot; noScrollBar style=&quot;width: 200px&quot;></textarea>
   </td>
  </tr>
  <tr>
   <td colspan=&quot;2&quot; align=&quot;center&quot;>
	<input class=&quot;button&quot; name=&quot;submit&quot; type=&quot;submit&quot; value=&quot;Send&quot; onClick=&quot;MM_validateForm('name','','R','emailFrom','','RisEmail');return document.MM_returnValue&quot;>
   </td>
  </tr>
 </table>
</form>
 </tr>
</table>
</body>
</html>

<%
Else
	' Send our message:
	' Note that I'm using the Win2000 CDO and not CDONTS!
	Set objCDO = Server.CreateObject(&quot;CDO.Message&quot;)
	With objCDO
		.To       = strTo
		.Cc       = strCc
		.From     = str_EmailAddress
		.Subject  = strSubject
		.HtmlBody = strBody
		.Send
	End With
	Set objCDO = Nothing
%>
<table width=&quot;60%&quot; align=&quot;center&quot;>
 <tr align=&quot;center&quot;>
  <td class=&quot;head&quot; align=&quot;center&quot;>Email sent, Thank you
  </td>
 </tr>
</table>
</body>
</html>
<%
	end if
%>

thanks for any help in advance!

annie
 
Hi

My understanding od CDO for Win2K is that you need to create a Server.CreateObject(&quot;CDO.Configuration&quot;) object as well.

Digga

Sharing Knowledge Saves Valuable Time!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top