Contact form

jimsau

Perch
Whats the best way to set up a contact form for an asp page to keep our e-mail from appearing or being listed?
 
What you need is a basic mailform script, but if it isn't already the case, modify it so that the destination e-mail address is fixed and determined in the script itself, not in your HTML code.

This way your script can't be abused by third parties and your own e-mail address is hidden, until you reply to such an e-mail of course :)
 
I wrote this a while back... should work okay for ya... written in ASP (VBScript)...


Code:
<%
sub sendmail(byval sendTo,byval sendFrom,byval sendSubject,byval sendBody,byval sendFormat,byref bitError,byref strResponse)
	bitError=false
	strResponse=""
	on error resume next
	set CDONTS=CreateObject("CDONTS.NewMail")
	with CDONTS
		.From=sendFrom
		.To=sendTo
		.Subject=sendSubject
		
		if sendFormat=0 then sendBody=replace(sendBody,"<br>",vbcrlf)
		
		.Body=sendBody
		.BodyFormat=0
		if sendFormat=0 then
			'text
			.MailFormat=1
		else
			'html
			.MailFormat=0
		end if
		.Importance=1
		
		.Send
		
		
	end with
	set CDONTS=Nothing
	if err<>0 then
			bitError=true
			strResponse=err.description
	end if
	on error goto 0
end sub

function checkemail(email)
	if len(email)<6 then
		checkemail=false
	else
		atsign=instr(2,email,"@")
		if atsign=0 then
			checkemail=false
		else
			dotsymbol=instr(cint(atsign)+2,email,".")
			if dotsymbol=0 then
				checkemail=false
			elseif cint(dotsymbol)+1>len(email) then
				checkemail=false
			elseif instr(email," ") then
				checkemail=false
			else
				checkemail=true
			end if
		end if
	end if
end function


bitSubmitted=false
bitSent=false
if len(request.form)>0 then
	bitSubmitted=true
	from=trim(request.form("from"))
	recipient=request.form("recipient")
	
	select case recipient
		case "jimsau"
			recipientemail="[email protected]"
	end select
	
	subject=trim(request.form("subject"))
	if len(subject)=0 or lcase(subject)="[none]" then subject="[none]"
	body=trim(request.form("body"))
	sendashtml=request.form("sendashtml")
	if len(sendashtml)>0 then sendashtml=1 else sendashtml=0
	sendcopy=request.form("sendcopy")
	
	if len(from)>0 and checkemail(from) and len(recipient)>0 and len(subject)>0 and len(body)>0 then
		bitThisError=false
		strThisResponse=""
		call sendmail(recipientemail,from,subject,"This email was sent from http://www.jimsau.com<br>---------------------------------------------<br><br>"&body,sendashtml,bitThisError,strThisResponse)
		if not bitThisError then bitSent=true
		
		
		if len(sendCopy)>0 then
			'on error resume next
			call sendmail(from,from,"Copy: "&subject,"Here is a copy of your email sent to "&recipient&" on "&now&"<br> - Sent from http://www.jimsau.com<br>---------------------------------------------------------------------<br><br>"&body,sendashtml,bitThisError,strThisResponse)
			'on error goto 0
		end if
	else
		if len(from)=0 then bitErrorFrom=true
		if not checkemail(from) then bitErrorFrom=true
		if len(recipient)=0 then bitErrorRecipient=true
		if len(subject)=0 then bitErrorSubject=true
		if len(body)=0 then bitErrorBody=true
	end if
else
	from=trim(request.querystring("from"))
	recipient=trim(request.querystring("to"))
	subject=trim(request.querystring("subject"))
	body=trim(request.querystring("body"))
end if
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title> jimsau.com - Contact Us </title>
<style>
	.redbg {
		background : cc0000;
	}
	body,td {
		font-family : verdana;
	}
</style>
<script>
function confirmReset(){
	var doReset=confirm("Reset Form?");
	if (doReset)
		document.location.href=document.location.href;
}
</script>
</head>
<body>
<%
if bitSubmitted then
	if bitSent then
		response.write "<div align=""center""><font size=""+1"" color=""#66cc00"" face=""verdana""><b>Your email has been sent to "&recipient&"!</b></font></div>"
	else
		response.write "<div align=""center""><font size=""+1"" color=""#cc0000"" face=""verdana""><b>Your email has not been sent to "&recipient&"!<br><br>"&strThisResponse&"</b></font></div>"
	end if
end if
%>
<font size="+1"><b>Contact Us</b><br><br>

<table border="1" cellspacing="0" cellpadding="4" bordercolor="#DDDDDD" bgcolor="#EEEEEE">
	<tr><form method="post" name="emailform" id="emailform">
		<td>
<table>
	<tr <%'if bitErrorFrom then response.write "bgcolor=""#FF6633"""%>>
		<td align="right">From:</td>
		<td><input type="text" name="from" value="<%=from%>" size="40" <%if bitErrorFrom then response.write "class=""redbg"""%>></td>
	</tr>
	<tr <%'if bitErrorRecipient then response.write "bgcolor=""#FF6633"""%>>
		<td align="right">To:</td>
		<td><select name="recipient">
		<option value="jimsau" <%if recipient="jimsau" then response.write "selected"%>>jimsau</option>
		</select></td>
	</tr>
	<tr <%'if bitErrorSubject then response.write "bgcolor=""#FF6633"""%>>
		<td align="right">Subject:</td>
		<td><input type="text" name="subject" size="40" value="<%=subject%>"></td>
	</tr>
	<tr <%'if bitErrorBody then response.write "bgcolor=""#FF6633"""%>>
		<td></td>
		<td><textarea cols="55" rows="10" name="body" <%if bitErrorBody then response.write "class=""redbg"""%>><%=body%></textarea></td>
	</tr>
	<tr>
		<td align="right" valign="top">Options:</td>
		<td><input type="checkbox" name="sendashtml" value="yes" <%if sendashtml=1 then response.write "checked"%>> Send this email as HTML<br>
		<input type="checkbox" name="sendcopy" value="yes" <%if len(sendcopy)>0 then response.write "checked"%>> Send a copy of this email to me</td>
	</tr>
</table>
		</td>
	</tr>
	<tr>
		<td><input type="submit" value="&nbsp;&nbsp;&nbsp;Send Email&nbsp;&nbsp;&nbsp;"> <input type="button" value="Reset" onClick="confirmReset();"></td>
	</form></tr>
</table>
<br><br>



</body>
</html>
 
Back
Top