我有一個表單驗證表單字段與JavaScript和發送電子郵件與VBScript。如何驗證工作正常,但電子郵件沒有發送到電子郵件帳戶。如何驗證表單和發送電子郵件
VBScript來發送電子郵件:
<%
posted = request.form ("submit")
if posted = "Submit" then
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'' Customize the following 5 lines with your own information. ''
''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
vtoaddress = "___________" ' Change this to the email address you will be receiving your notices.
vmailhost = "smtp.gmail.com" ' Change this to your actual Domain name.
vfromaddress = "___________" ' Change this to the email address you will use to send and authenticate with.
vfrompwd = "___________" ' Change this to the above email addresses password.
'''''''''''''''''''''''''''''''''''''''''''
'' DO NOT CHANGE ANYTHING PAST THIS LINE ''
'''''''''''''''''''''''''''''''''''''''''''
vsubject = request.form ("subject")
vfromname = request.form ("fname")
vbody = request.form ("message")
vrplyto = request.form ("email")
vrcity = request.form ("city")
vrmono = request.form ("phone")
vmsgbody = "<b>Name:</b> "& vfromname & "<br><b>Email:</b> "& vrplyto &"<br><b>Mobile No:</b> "& vrmono &"<br><b>City:</b> "& vrcity &"<br><b>Subject:</b> "& vsubject&"<br><b>Message:</b> "& vbody
Set objEmail = Server.CreateObject("CDO.Message")
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserver") = vmailhost
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = 1
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpconnectiontimeout") = 60
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendusername") = vfromaddress
objEmail.Configuration.Fields.Item ("http://schemas.microsoft.com/cdo/configuration/sendpassword") = vfrompwd
objEmail.Configuration.Fields.Update
objEmail.Subject = vsubject
objEmail.From = vfromaddress
objEmail.To=vfromaddress
objEmail.HTMLBody = vmsgbody
objEmail.Send
vErr = Err.Description
if vErr <> "" then
response.write vErr & "<br><br>There was an error on this page."
'MsgBox("There was an error on this page.")
else
response.write "Thank you, your message has been sent."
'MsgBox("Thank you, your message has been sent.")
End If
Set objEmail = Nothing
response.write "Thank you, your message has been sent."
'MsgBox("Thank you, your message has been sent.")
end if
%>
Javascript來驗證形式:
<script language="JavaScript">
<!--
function validate()
{
var count_bug=0;
if(document.form1.fname.value=="")
{
document.getElementById("alertMsgfname").innerHTML=" Enter Your First Name. ";
document.getElementById("alertMsgfname").style.visibility="visible";
if(eval(count_bug)==0)
document.form1.fname.focus();
count_bug+=1;
}
if(document.form1.email.value=="")
{
document.getElementById("alertMsgemail").innerHTML=" Enter Your E-mail. ";
document.getElementById("alertMsgemail").style.visibility="visible";
if(eval(count_bug)==0)
document.form1.email.focus();
count_bug+=1;
}
else if(!isEmail(document.form1.email.value))
{
document.getElementById("alertMsgemail").innerHTML=" Enter Valid E-mail! ";
document.getElementById("alertMsgemail").style.visibility="visible";
if(eval(count_bug)==0)
document.form1.email.focus();
count_bug+=1;
}
if(document.form1.phone.value=="")
{
document.getElementById("alertMsgphone").innerHTML=" Your Phone No. ";
document.getElementById("alertMsgphone").style.visibility="visible";
if(eval(count_bug)==0)
document.form1.phone.focus();
count_bug+=1;
}
else if(!ValidateNo(document.form1.phone.value," 1234567890,-/+"))
{
document.getElementById("alertMsgphone").innerHTML=" Invalid Phone No. ";
document.getElementById("alertMsgphone").style.visibility="visible";
if(eval(count_bug)==0)
document.form1.phone.focus();
count_bug+=1;
}
else if(document.form1.phone.value.length < 5)
{
document.getElementById("alertMsgphone").innerHTML=" Invalid Phone No. ";
document.getElementById("alertMsgphone").style.visibility="visible";
if(eval(count_bug)==0)
document.form1.phone.focus();
count_bug+=1;
}
if(document.form1.city.value=="")
{
document.getElementById("alertMsgCity").innerHTML=" Enter Your City Name. ";
document.getElementById("alertMsgCity").style.visibility="visible";
if(eval(count_bug)==0)
document.form1.city.focus();
count_bug+=1;
}
if(document.form1.subject.value=="")
{
document.getElementById("alertMsgSubject").innerHTML=" Enter Your Subject. ";
document.getElementById("alertMsgSubject").style.visibility="visible";
if(eval(count_bug)==0)
document.form1.subject.focus();
count_bug+=1;
}
if(document.form1.message.value=="")
{
document.getElementById("alertMsgMessage").innerHTML=" Enter Your Message. ";
document.getElementById("alertMsgMessage").style.visibility="visible";
if(eval(count_bug)==0)
document.form1.message.focus();
count_bug+=1;
}
if(count_bug>0)
return false;
else
return true;
}
function isEmail (emailIn){
var isEmailOk = false;
var filter = /^[a-zA-Z0-9][a-zA-Z0-9._-]*\@[a-zA-Z0-9-]+(\.[a-zA-Z][a-zA-Z-]+)+$/
// var filter = /^(([^<>()[\]\\.,;:\[email protected]\」]+(\.[^<>()[\]\\.,;:\[email protected]\」]+)*)|(\」.+\」))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/
if(emailIn.search(filter) != -1)
isEmailOk = true;
if(emailIn.indexOf("..") != -1)
isEmailOk = false;
if(emailIn.indexOf("[email protected]") != -1)
isEmailOk = false;
return isEmailOk;
}
function ValidateNo(NumStr, String)
{
for(var Idx = 0; Idx < NumStr.length; Idx ++)
{
var Char = NumStr.charAt(Idx);
var Match = false;
for(var Idx1 = 0; Idx1 < String.length; Idx1 ++)
{
if(Char == String.charAt(Idx1))
Match = true;
}
if (!Match)
return false;
}
return true;
}
</script>
HTML形式的代碼:
<form name="form1" method="post" onsubmit="return validate();">
<table border="0" width="100%" cellspacing="0" cellpadding="0" class="table-format">
<tr valign="middle">
<td align="left" class="text-fm" width="23%" style="padding-top:8px;">
<b>Name<font color="#C70017">*</font></b></td>
<td align="left" class="text-fm" width="5%">
<b>:</b></td>
<td class="text-fm" align="left">
<input type="text" name="fname" id="fname" size="43" maxlength="40" class="inp">
<span id="alertMsgfname" class="valfrm" style='line-height:8px;'></span></td>
</tr>
<tr valign="middle">
<td align="left" class="text-fm" style="padding-top:8px;">
<b>Email Id<font color="#C70017">*</font></b></td>
<td align="left" class="text-fm">
<b>:</b></td>
<td class="text-fm" align="left">
<input type="text" name="email" id="email" size="43" maxlength="76" class="inp">
<span id="alertMsgemail" class="valfrm" style='line-height:8px;'></span></td>
</tr>
<tr valign="middle">
<td align="left" class="text-fm" style="padding-top:8px;">
<b>Mobile No.<font color="#C70017">*</font></b></td>
<td align="left" class="text-fm">
<b>:</b></td>
<td class="text-fm" align="left">
<input type="text" name="phone" id="phone" size="43" maxlength="16" class="inp">
<span id="alertMsgphone" class="valfrm" style='line-height:8px;'></span></td>
</tr>
<tr valign="middle">
<td align="left" class="text-fm" style="padding-top:8px;">
<b>City<font color="#C70017">*</font></b></td>
<td align="left" class="text-fm">
<b>:</b></td>
<td class="text-fm" align="left">
<input type="text" name="city" id="city" size="43" maxlength="76" class="inp">
<span id="alertMsgCity" class="valfrm" style='line-height:8px;'></span></td>
</tr>
<tr valign="middle">
<td align="left" class="text-fm" style="padding-top:8px;">
<b>Subject<font color="#C70017">*</font></b></td>
<td align="left" class="text-fm">
<b>:</b></td>
<td class="text-fm" align="left">
<input type="text" name="subject" id="subject" size="43" maxlength="76" class="inp">
<span id="alertMsgSubject" class="valfrm" style='line-height:8px;'></span></td>
</tr>
<tr valign="middle">
<td align="left" class="text-fm" style="padding-top:8px;">
<b>Message<font color="#C70017">*</font></b></td>
<td align="left" class="text-fm">
<b>:</b></td>
<td class="text-fm" align="left">
<textarea name="message" id="message" size="43" maxlength="16" class="inp" rows="6" cols="30"></textarea>
<span id="alertMsgMessage" class="valfrm" style='line-height:8px;'></span></td>
</tr>
<tr>
<td align="left" colspan="3">
<div align="center"><br>
<input type="submit" value="" name="Submit" class="imgClass"/>
<br>
</td>
</tr>
</table>
</form>
所以你配置了你的smtp細節?請修改您的帖子以僅顯示相關代碼 – 2013-05-17 10:42:13
我無法輸入電子郵件地址和密碼。 –