0

javascript でフォーム フィールドを検証し、VBscript で電子メールを送信するフォームが 1 つあります。検証は正常に機能しますが、電子メールは電子メール アカウントに送信されません。

電子メールを送信する 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="&nbsp;Enter Your First Name.&nbsp;";
            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="&nbsp;Enter Your E-mail.&nbsp;";
            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="&nbsp;Enter Valid E-mail!&nbsp;";
            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="&nbsp;Your Phone No.&nbsp;";
            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="&nbsp;Invalid Phone No.&nbsp;";
            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="&nbsp;Invalid Phone No.&nbsp;";
            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="&nbsp;Enter Your City Name.&nbsp;";
            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="&nbsp;Enter Your Subject.&nbsp;";
            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="&nbsp;Enter Your Message.&nbsp;";
            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 = /^(([^<>()[\]\\.,;:\s@\”]+(\.[^<>()[\]\\.,;:\s@\”]+)*)|(\”.+\”))@((\[[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(".@") != -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>
4

1 に答える 1