Javascript 如何验证表单和发送电子邮件

Javascript 如何验证表单和发送电子邮件,javascript,asp-classic,vbscript,Javascript,Asp Classic,Vbscript,我有一个表单,用javascript验证表单字段,用VBscript发送电子邮件。如何验证工作正常,但电子邮件未发送到电子邮件帐户 发送电子邮件的脚本: <% posted = request.form ("submit") if posted = "Submit" then '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''' '' Customize the following 5 lines with yo

我有一个表单,用javascript验证表单字段,用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
%>

没有错误描述并不意味着没有错误。将错误处理代码更改为:

If Err Then
    response.write Err.Number & "<br><br>There was an error on this page."
Else
    response.write "Thank you, your message has been sent."
End If
您使用的凭据是否正确


您有权访问邮件服务器日志吗?他们对该页面的连接怎么说?如果您无法访问实际的邮件服务器,是否可以设置一个虚拟服务器并将页面临时指向该服务器,以便检查代码是否正常工作?

那么您是否配置了smtp详细信息?请编辑您的帖子,仅显示相关代码。我无法输入电子邮件地址和密码。我可以使用正确的凭据连接此端口。有了安全性,我才不会用密码。当我使用简单表单时,电子邮件成功发送到发件人地址,而不使用onsubmit=“return validate();”和javascript。然后我会尝试简化javascript代码。将验证函数更改为
函数validate(){return true;}
时会发生什么情况?
<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>
If Err Then
    response.write Err.Number & "<br><br>There was an error on this page."
Else
    response.write "Thank you, your message has been sent."
End If
telnet smtp.gmail.com 465