PDA

View Full Version : Email Verification


sutton silver
09-08-2008, 10:48 AM
I'm sure it's a thread that's been raised a few times...

I have created a form which carries the hidden values across through multiple pages, then submits the whole thing to the admin when all fields are filled in.

I'm looking for a quick-fix email verification solution which verfies the users-input email address...at present, if the user misspells their email or it bounces back from the server, the error ('8004020e' blablabla.asp line blabla) occurs..

Here's the HTML for the form (Yes I know it's table, it's not my work, will update it all eventually)


<html>
<head>
<title>Creative Mortgage Solutions | Apply online</title>
<meta http-equiv="imagetoolbar" content="no">
<link href="css/popupmenu.css" rel="stylesheet" type="text/css">
<script language="JavaScript" src="java/stoprightclickmouse.js"></script>
<script language="JavaScript">
function validate(f) {
if (f.x1_Company.value=="" || f.x1_Company.value==null) { alert("You must enter your company name."); return false }
if (f.x1_Name.value=="" || f.x1_Name.value==null) { alert("You must enter your name."); return false }
if (f.x1_Telephone.value=="" || f.x1_Telephone.value==null) { alert("You must enter your telephone number."); return false }
if (f.x1_Email.value=="" || f.x1_Email.value==null) { alert("You must enter your email address."); return false }
return true;
}
</script>
</head>

<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
var pageTracker = _gat._getTracker("UA-2759099-6");
pageTracker._initData();
pageTracker._trackPageview();
</script>

<body class="PageBACKGROUND">
<a name="PageTOP"></a>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="bottom"><img src="css/images/cms_header_1.png" alt="Creative Mortgage Solutions">
</td>

</tr>
</table>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top"><img src="css/images/shim.gif" width="1" height="10"></td>
</tr>
</table>
<table width="90%" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td align="left" valign="top">
<p class="TextTITLE">Apply online</p>
<p class="TextPARAGRAPH">For Residential and Buy-To-Let enquiries only. </p>
<p class="TextPARAGRAPH">For Second Charge, Bridging Finance, and Commercial Mortgage enquiries please click <a href="http://cmschester.com/download_centre.html" target="_blank">here</a></p>
<p class="TextPARAGRAPH"><strong>All applicable fields are compulsory and must be fully completed to ensure that we provide you with correct options for your client(s). </strong></p></td>
</tr>
</table>

<form action="form2.asp" method="post" name="form1" target="_self" id="form1" onSubmit="return validate(this)">
<table width="90%" border="0" align="center" cellpadding="5" cellspacing="0" class="TextPARAGRAPH">
<tr align="left">
<td colspan="4" align="left">
<p class="TextTITLE">Step 1: Broker information.</p>
</td>
</tr>
<tr align="left">
<td width="300" align="left"><strong>Company</strong></td>
<td colspan="3">
<input type="text" name="x1_Company" class="FormSINGLE">
</td>
</tr>
<tr align="left">

<td width="300" align="left"><strong>Name</strong></td>
<td colspan="3">
<input type="text" name="x1_Name" class="FormSINGLE">
</td>
</tr>
<tr align="left">
<td width="300" align="left"><strong>Telephone</strong></td>
<td colspan="3">
<input type="text" name="x1_Telephone" class="FormSINGLE">
</td>
</tr>
<tr align="left">
<td width="300" align="left"><strong>Fax</strong> </td>

<td colspan="3">
<input type="text" name="x1_Fax" class="FormSINGLE">
</td>
</tr>
<tr align="left">
<td width="300" align="left"><strong>Email</strong></td>
<td colspan="3">
<input type="text" name="x1_Email" class="FormSINGLE">
</td>
</tr>

</table>
<table width="90%" border="0" align="center" cellpadding="5" cellspacing="0" class="TextPARAGRAPH">
<tr align="left">
<td align="left"><img src="../assets/images/shim.gif" width="1" height="10"></td>

</tr>
<tr align="left">
<td align="left">
<input name="Submit" type="submit" class="FormBUTTON" value="Next">
</td>
</tr>
<tr align="left">
<td align="left"><img src="css/images/shim.gif" width="1" height=10"></td>
</tr>
<tr align="left">
<td align="left" class="Border6699FF"><strong>HINT: </strong>On the next page, you will be asked for the <strong>loan</strong> details.</td>
</tr>

</table>
</form>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top"><img src="css/images/shim.gif" width="1" height="30"></td>
</tr>
</table>
<table width="90%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="top">
<p class="Text999999">This web site is published by Creative Mortgage Solutions Ltd., Flavell Suite, Redhill House, Hope Street, Chester, CH4 8BU and is for the use of FSA mortgage intermediaries only. It does not constitute an advertisement under the Consumer Credit Act 1974. Creative Mortgage Solutions Ltd. will not enter into communication with persons other than those authorised to give advice by the FSA. Every effort is made to ensure the accuracy of the information we publish. However, we accept no liability or responsibility for its accuracy.</p>
</td>
<td width="25" align="right" valign="top"><a href="#PageTOP" target="_self"><img src="css/images/article_bar_top.gif" alt="Back to page top" width="15" height="17" border="0"></a></td>
</tr>

</table>

</body>
</html>



And the ASP which the values are sent to...

<%

' declare variables
Dim EmailTo
Dim Subject
Dim x1_Company
Dim x1_Name
Dim x1_Telephone
Dim x1_Fax
Dim x1_Email

' get posted data into variables
EmailTo = sample@emailaddressofrecipient.co.uk"
Subject = "Online AIP form enquiry"
x1_Company = Trim(Request.Form("x1_Company"))
x1_Name = Trim(Request.Form("x1_Name"))
x1_Telephone = Trim(Request.Form("x1_Telephone"))
x1_Fax = Trim(Request.Form("x1_Fax"))
x1_Email = Trim(Request.Form("x1_Email"))

' validation
Dim validationOK
validationOK=true
If (Trim(x1_Email)="") Then validationOK=false
If (validationOK=false) Then Response.Redirect("tryagain.asp")

' prepare email body text
Dim Body
Body = Body & "Broker Information: " & VbCrLf & VbCrLf
Body = Body & x1_Company & VbCrLf
Body = Body & x1_Name & VbCrLf
Body = Body & x1_Telephone & VbCrLf
Body = Body & x1_Fax & VbCrLf
Body = Body & x1_Email & VbCrLf & VbCrLf
Body = Body & "............................................... " & VbCrLf & VbCrLf

'response.write Body

' send email
' Dim mail
' Set mail = Server.CreateObject("CDONTS.NewMail")
' mail.To = EmailTo
' mail.From = x1_Email
' mail.Subject = Subject
' mail.Body = Body
' mail.Send

Dim sch, cdoConfig, cdoMessage
sch = "http://schemas.microsoft.com/cdo/configuration/"

Set cdoConfig = CreateObject("CDO.Configuration")

With cdoConfig.Fields
.Item(sch & "sendusing") = 2
.Item(sch & "smtpserver") = "localhost"
.update
End With

Set cdoMessage = CreateObject("CDO.Message")

With cdoMessage
Set .Configuration = cdoConfig
.From = x1_Email
.To = EmailTo
.Subject = Subject
.TextBody = Body
.Send
End With

Set cdoMessage = Nothing
Set cdoConfig = Nothing

' redirect to success page
'Response.Redirect("confirmation.asp")
%>

Sorry about all the values... I'm sure there is just a small piece of the puzzle I need to get this verification working, I have scoured the internet but couldn't make head-nor-tale out of most of the tutorials...

Cheers
Chris SS

Spudhead
09-08-2008, 03:03 PM
Not entirely clear on what you want, but... here's a simple function that'll run an email address past a regular expression:

function isValidEmail(sEmail)
dim rv : rv = true
dim regEx
set regEx = New RegExp
regEx.IgnoreCase = False
regEx.Pattern = "^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$"
rv = regEx.Test(sEmail)
set regEx = nothing
isValidEmail = rv
end function


You could replace this line:

If (Trim(x1_Email)="") Then validationOK=false

with

If not isValidEmail(x1_Email) Then validationOK = false

Is that any use?


Oh - ps: unless you've got a thing for spam, I'd take your email out of the code you posted :)

sutton silver
09-08-2008, 04:07 PM
Basically I keep getting an error at the final submission stage of the form (page 8 of the form) and it refers to a line in the code which sends the email.

I have researched it and I have found out it's something to do with the email not being verified, everytime I use an email that I know works, the email is sent and the form works, everytime I use an email that I have just made up on the spot, it doesn't work.

I will attempt to implement this code, and let you know how I got on!
Cheers
C SS