Avatar of HSI_guelph
HSI_guelph
Flag for Canada asked on

Trying to modify a page to get emails from people but not working

I am trying to take an existing webpage that sends an email to a recipient from our website without needing the user to have Outlook installed and use it to make a new page.  

<%@ Language=VBScript %>
<%Response.expires=0%>
<!-- #include file="Connection.asp" -->
<%
if request("name") <> "" then
	name = request("name")
	position = request("position")
	company = request("company")
	email = request("email")
	phone = request("phone")
	address = request("address")
	city = request("city")
	province = request("province")
	postalcode = request("postalcode")
	country = request("country")
	comments = request("comments")
	recipient = request("recipient")
	
	sql="select * from tblContact where 1=1"
	
	rs.open sql,cn,2,3
	rs.addnew
	rs("name")= name
	rs("position")=position
	rs("company")=company
	rs("email")=email
	rs("phone")=phone
	rs("address")=address
	rs("city")=city
	rs("province")=province
	rs("postalcode")=postalcode
	rs("country")=country
	rs("comments")=comments
	rs("recipient")=recipient
	
	rs.update
	rs.close
	
	'MailBody=Name
	'MailBody=MailBody & "<BR><BR>"
	'MailBody=MailBody & "Thank you for contacting us. We will be in touch with you soon." 'Thanks for contacting us. We will revert back to you soon.
	'MailBody=MailBody & "<BR><BR>"
	'MailBody=MailBody & "Company<sup>®</sup> Incorporated"

	'Set MyCDOSYSMail = CreateObject("CDO.Message")
	'MyCDOSYSMail.from= recipient & "@company.com"'Application("CustomerEmail")
	'MyCDOSYSMail.To= email

	'MyCDOSYSMail.Subject= "Thanks for Contacting us."
	'MyCDOSYSMail.HTMLBody= MailBody
	'MyCDOSYSMail.Send
	'set MyCDOSYSMail=nothing	
	
	MailBody="Following contact form details have been submitted by a user on Company.com."
	MailBody=MailBody & "<BR><BR>"
	MailBody=MailBody & "Contact Name: " & name & "<BR>"
	MailBody=MailBody & "Position: " & position & "<BR>"
	MailBody=MailBody & "Company: " & company & "<BR>"
	MailBody=MailBody & "Email: " & email & "<BR>"
	MailBody=MailBody & "Phone: " & phone & "<BR>"
	MailBody=MailBody & "Address: " & address & "<BR>"
	MailBody=MailBody & "City: " & city & "<BR>"
	MailBody=MailBody & "Province/State: " & province & "<BR>"
	MailBody=MailBody & "Contact Name: " & name & "<BR>"
	MailBody=MailBody & "Postal Code/ZIP: " & postalcode & "<BR>"
	MailBody=MailBody & "Country: " & country & "<BR><BR>"
	MailBody=MailBody & "Comments: " & Comments & "<BR>"
	MailBody=MailBody & "<BR><BR>"
	MailBody=MailBody & "Company<sup>®</sup> Incorporated"

	Set MyCDOSYSMail = CreateObject("CDO.Message")
	MyCDOSYSMail.from= email
	MyCDOSYSMail.To= recipient & "@company.com"
	
	MyCDOSYSMail.Subject= "Thanks for Contacting us."
	MyCDOSYSMail.HTMLBody= MailBody
	MyCDOSYSMail.Send
	set MyCDOSYSMail=nothing
	
	response.redirect ("contactform.asp?msg=1")
end if
msg = request("msg")%>

Open in new window


I've modified the code to remove what looks like sql to update a table (?) and altered it for my current form:
<%@ Language=VBScript %>
<%

if request("lastname") <> "" then
	response.write("Yes this is working")
	objMessage.Send
	MailBody="Following person would like to give consent for us to contact them."
	MailBody=MailBody & "<BR><BR>"
	MailBody=MailBody & "Last Name: " & request("lastname") & "<BR>"
	MailBody=MailBody & "First Name: " & request("firstname") & "<BR>"
	MailBody=MailBody & "Position: " & request("position") & "<BR>"
	MailBody=MailBody & "Company: " & request("company") & "<BR>"
	MailBody=MailBody & "Email: " & request("email") & "<BR>"
	MailBody=MailBody & "Phone: " & request("phone") & "<BR>"
	MailBody=MailBody & "Address: " & request("address") & "<BR>"
	MailBody=MailBody & "City: " & request("city") & "<BR>"
	MailBody=MailBody & "Province/State: " & request("province") & "<BR>"
	MailBody=MailBody & "Postal Code/ZIP: " & request("postalcode") & "<BR>"
	MailBody=MailBody & "Country: " & request("country") & "<BR><BR>"
	MailBody=MailBody & "<BR><BR>"
	MailBody=MailBody & "company <sup>®</sup> Incorporated"

	Set MyCDOSYSMail = CreateObject("CDO.Message")
	MyCDOSYSMail.From = """Sender Name"" <itsupport@company.com>" 
	MyCDOSYSMail.To= "me@company.com"
	
	MyCDOSYSMail.Subject= "Thanks for Contacting us."
	MyCDOSYSMail.HTMLBody= MailBody
	MyCDOSYSMail.Send
	set MyCDOSYSMail=nothing
	msg = "Thank you for your interest"
	response.redirect ("consentform.asp")
end if
%>

Open in new window


If I remove the 'if' statement it will send an email with empty data when the page loads or is refreshed but for some reason it won't work with the if.  

if request("lastname") <> "" then - this tells me it's seeing if anything has been entered into the last name form box of that name.  If I change it to = "" it works but obviously that is not how it should work.  I tried giving the form element a value  <input type="text" name="lastname" class="myforms" maxlength=50 size=50 value=""> but no luck.

Does anyone have any suggestions on how to get this to work?  I'll add the form code and the JavaScript in case I'm missing something in them.

<form name="frm" action="consentform.asp" method="Post">
<tr>
	<td width="25%"></td>
		<td width="75%" align="right"><font class="general">Fields marked with <font class="redfont">*</font> are required.</font></td>
	</tr>
<tr>
	<td width="25%" height="10"></td>
		<td width="75%"></td>
</tr>
<tr>
	<td width="25%"><font class="general">Last Name:</font>&nbsp;<font class="redfont">*</font></td>
		<td width="75%"><input type="text" name="lastname" class="myforms" maxlength=50 size=50 value=""></td>
</tr>
<tr>
	<td><font class="general">First Name:</font>&nbsp;<font class="redfont">*</font></td>
		<td><input type="text" name="firstname" class="myforms" maxlength=50 size=50></td>
</tr>
<tr>
	<td><font class="general">Position:</font>&nbsp;<font class="redfont">*</font></td>
		<td><input type="text" name="position" class="myforms" maxlength=50 size=50></td>
</tr>
<tr>
	<td><font class="general">Company:</font>&nbsp;<font class="redfont">*</font></td>
		<td><input type="text" name="email" class="myforms" maxlength=50 size=50></td>
</tr>
<tr>
	<td><font class="general">Email:</font>&nbsp;<font class="redfont">*</font></td>
		<td><input type="text" name="email" class="myforms" maxlength=50 size=50></td>
</tr>
<tr>
	<td><font class="general">Phone:</font>&nbsp;<font class="redfont">*</font></td>
		<td><input type="text" name="phone" class="myforms" maxlength=50 size=50></td>
</tr>
<tr>
	<td><font class="general">Address:</font></td>
		<td><input type="text" name="address" class="myforms" maxlength=50 size=50></td>
</tr>
<tr>
	<td><font class="general">City:</font></td>
		<td><input type="text" name="city" class="myforms" maxlength=255 size=50></td>
</tr>
<tr>
	<td><font class="general">Province/State:</font></td>
		<td><input type="text" name="province" class="myforms" maxlength=50 size=50></td>
</tr>
<tr>
	<td><font class="general">Postal Code/ZIP:</font></td>
		<td><input type="text" name="postalcode" class="myforms" maxlength=10 size=50></td>
</tr>
<tr>
	<td><font class="general">Country:</font></td>
		<td><input type="text" name="country" class="myforms" maxlength=50 size=50></td>
</tr>
<tr>
<td colspan="2">&nbsp;</td>
</tr>
<tr>
<td colspan=2 align="center" height=50 valign="middle">
	<!--- <INPUT type=image alt=Submit src="images/english/site/submit_button.gif" border=0> --->
	<a onClick="return chklogin();" href="#"><img src="images/english/site/submit_button.gif" border=0 alt="Submit"></a>
	<!-- Comments Ends By VL07 on 11-08-2005 -->
	<a onClick="document.frm.reset();return false;" href="#"><img src="images/english/site/reset_button.gif" border="0"></a>
</td>
</tr>
</form>

Open in new window


<script language="JavaScript" type="text/JavaScript">
<!--
function MM_preloadImages() { //v3.0
  var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
    var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
    if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}

function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>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_swapImgRestore() { //v3.0
  var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}

function MM_swapImage() { //v3.0
  var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
   if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<script language="JavaScript" src="CheckFormFlds.js"></script>
<script language="javascript">
	function chklogin()
	{
		if(CheckFields("name","text",50,"Contact Name")==false) return false
		if(CheckFields("position","text",50,"Position")==false) return false
		if(CheckFields("company","text",50,"Company")==false) return false
		if(CheckFields("email","email",50,"Email")==false) return false
		document.frm.submit()
		//return true
	} 
</script>

Open in new window

VB Script

Avatar of undefined
Last Comment
HSI_guelph

8/22/2022 - Mon
chaau

Your "chklogin" javascript function checks these fields: name, position, company, email. However, it looks like there is no input field called "name" on your form. Also, there are two elements with the name "email". It is not clear what the function "CheckFields" will do in this case.
BTW, all your input elements have only "name" attribute. This means that "CheckFields" must use "getElementByName". Please check its code and find out what it uses. If it uses "getElementById" then you will have to add "id" attribute to all of your input elements (always a good idea anyway)
ASKER CERTIFIED SOLUTION
chaau

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
HSI_guelph

ASKER
Yay!  That did it!  Thank you very much!
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy