Solved

Form Mail

Posted on 2004-04-15
21
233 Views
Last Modified: 2011-08-18
Hello,

I am working on trying to add a form mail to my website. I have a list menu in my form. I would like to be able to submit the request to the individual selected in my list menu. Therefore, my receipient field has to be dynamic depending on the selection. How can I accomplish this?
0
Comment
Question by:contesa
  • 12
  • 8
21 Comments
 
LVL 4

Expert Comment

by:monolith_888
ID: 10834090
=========
In your HEAD:
=========
<script>
function sendMail()
  {
  var theForm = document.myForm;
  var recip = theForm.mailList.options[theForm.mailList.selectedIndex].text;

  theForm.action = "mailto:"+recip;
  alert('will mail to: '+recip);
  return true;      
  }
</script>

=========
in your BODY:
=========
<form name="myForm" onSubmit="return sendMail();">
<select name="mailList">
  <option>joe@someone.com</option>
  <option>frank@someone.com</option>
  <option>mary@someone.com</option>
</select>
<input type="submit" value="send">
</form>

-hth
monolith
0
 

Author Comment

by:contesa
ID: 10836385
Thank you for responding so quickly. I tested the code; however, it launches my email client in order to send the message. In addition, it doesn't automatically include the sender's email address in the to fiield of the message. Is there another way where either the email could be automatically added to the to: field in the message or completely avoid launching my email client.

I must inform you that I am new to programming so I will need to see examples of code.
0
 
LVL 2

Expert Comment

by:sc0rp10n
ID: 10838591
contesa,

Are you using any web technology like PHP, ASP, .NET, JSP, etc or just plain on HTML/Javascript?
0
 

Author Comment

by:contesa
ID: 10842294
Hi sc0rp10n,

No I am currently not using any web technology. I am very new to this field as you can tell.  My web server is a Windows 2000 server.  My network manager set up the server and I am not sure what's loaded on the server. However, I'm sure that I can get him to load whatever I need.

I am just using HTML/Javascript at the current time.

0
 

Author Comment

by:contesa
ID: 10843936
Below is the code for my form. It's a simple form. However, I would like to eliminate the script I'm using for sending mail because it launches the email client. As you can see, there is a drop down list. When the user makes a selection and fills out the form, I want the email to be sent to that person.

I also want to be able to automatically generate a service tracking number.  In the future, I would like to dump this information into a database. But not right now.  I just want to get these two features working as soon as possible. I don't have anything included for form action because I don't know which scripting language would be best. I would like the script to process both the send mail and the automatic numbering. Is that possible? Again, I'm a newbie.. :-)

I am running on a Windows 2000 Server/IIS.  Not sure what my network manager has installed on the server. But he will install whatever I need.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script>
function sendMail()
      {
      var theForm = document.myForm;
      var recip = theForm.mailList.options[theForm.mailList.selectedIndex].text;
      
      theForm.action = "mailto:"+recip;
      alert('will mail to: '+recip);
      return true;
      }
</script>
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
      color: #000000;
      font-weight: bold;
}
-->
</style>
</head>

<body><form action="" method="post" enctype="multipart/form-data" name="myForm" onSubmit="return sendMail();">
  <table width="500" border="1" align="center">
    <tr>
      <td colspan="5"><table width="100%"  border="0" align="center">
          <tr>
            <td colspan="2"><div align="center" class="style1">Information Technology Management &amp; Support<br>
  SERVICE REQUEST </div></td>
          </tr>
          <tr>
            <td width="18%">Request No.</td>
            <td width="82%">&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td width="121"><div align="center">DATE</div></td>
      <td width="152"><div align="center">REQUESTOR</div></td>
      <td width="100"><div align="center">BUREAU</div></td>
      <td width="99" colspan="2"><div align="center">PHONE # </div></td>
    </tr>
    <tr>
      <td><div align="center">
        <input name="date" type="text" id="date" size="20" maxlength="20">
      </div></td>
      <td><div align="center">
        <input name="requestor" type="text" id="requestor" size="20" maxlength="20">
      </div></td>
      <td><div align="center">
        <select name="mailList">
          <option value="kathy.coates@njdge.org">ADM</option>
          <option value="dan.kelly@njdge.org">CEB/NJSP</option>
          <option value="paul.kuras@njdge.org">CIU</option>
          <option value="ted.grove">CJ</option>
          <option value="mike.romano@njdge.org">CLS</option>
          <option value="jean.escarpeta@njdge.org">ELS</option>
          <option value="rich.handzo@njdge.org">REB</option>
          <option value="debbie.algor@njdge.org">REC/ID</option>
          <option value="al.white@njdge.org">SILS</option>
          <option value="rich.williamson@njdge.org">TSB</option>
          <option value="willie.johnson@njdge.org">TEST</option>
              <option value="jon.rocque@njdge.org">TEST2</option>
        </select>
      </div></td>
      <td colspan="2"><div align="center">
        <input name="phone_no" type="text" id="phone_no" size="10" maxlength="10">
      </div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center"><strong>SERVICES REQUESTED </strong></div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center">
        <textarea name="services_requested" cols="60" id="services_requested"></textarea>
      </div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center"><strong>JUSTIFICATION</strong></div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center">
        <textarea name="justification" cols="60" id="justification"></textarea>
      </div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center">
        <input type="submit" value="send">
      </div></td>
    </tr>
  </table>
</form>
</body>
</html>
0
 
LVL 2

Accepted Solution

by:
sc0rp10n earned 500 total points
ID: 10855908
Hi contesa,

At this moment, I believe, using ASP as a web technology is the easy way to go. I recommed this as you are using Windows 2000 server with IIS. So you already have it. Also, you should have a mail server. So make sure the mail server is enabled. Your administrator should do this.

After making sure the mail server is set, save the following code as sendrequest.asp under %IISROOT%/wwwroot/ directory (typically c:\inetpub\wwwroot\sendrequest.asp). And in the browser go to: http://<servername>/sendrequest.asp

To start with, this should bring up the form that you've set-up, fill in all the details and hit submit. MAKE SURE THAT the REQUESTOR textbox has an actuall email, or else the mail send can fail. Once you hit the send button, and mail is sent, you should get a Mail sent to <whoever> message.

I hope this whole thing makes sense.
hth
AJ

-- start code sendrequest.asp --

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Send Service Request</title>
<%
      response.buffer=true
   
      Func = Request("Func")
          
      if isempty(Func) then
                Func = 1
      end if

    Select case Func
            case 1
    %>
<style type="text/css">
<!--
.style1 {
     color: #000000;
     font-weight: bold;
}
-->
</style>
</head>

<body><form action="sendrequest.asp?func=2" method="post" enctype="multipart/form-data" name="myForm">
  <table width="500" border="1" align="center">
    <tr>
      <td colspan="5"><table width="100%"  border="0" align="center">
          <tr>
            <td colspan="2"><div align="center" class="style1">Information Technology Management &amp; Support<br>
  SERVICE REQUEST </div></td>
          </tr>
          <tr>
            <td width="18%">Request No.</td>
            <td width="82%">&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td width="121"><div align="center">DATE</div></td>
      <td width="152"><div align="center">REQUESTOR</div></td>
      <td width="100"><div align="center">BUREAU</div></td>
      <td width="99" colspan="2"><div align="center">PHONE # </div></td>
    </tr>
    <tr>
      <td><div align="center">
        <input name="date" type="text" id="date" size="20" maxlength="20">
      </div></td>
      <td><div align="center">
        <input name="requestor" type="text" id="requestor" size="20" maxlength="20">
      </div></td>
      <td><div align="center">
        <select name="mailList">
          <option value="kathy.coates@njdge.org">ADM</option>
          <option value="dan.kelly@njdge.org">CEB/NJSP</option>
          <option value="paul.kuras@njdge.org">CIU</option>
          <option value="ted.grove">CJ</option>
          <option value="mike.romano@njdge.org">CLS</option>
          <option value="jean.escarpeta@njdge.org">ELS</option>
          <option value="rich.handzo@njdge.org">REB</option>
          <option value="debbie.algor@njdge.org">REC/ID</option>
          <option value="al.white@njdge.org">SILS</option>
          <option value="rich.williamson@njdge.org">TSB</option>
          <option value="willie.johnson@njdge.org">TEST</option>
            <option value="jon.rocque@njdge.org">TEST2</option>
        </select>
      </div></td>
      <td colspan="2"><div align="center">
        <input name="phone_no" type="text" id="phone_no" size="10" maxlength="10">
      </div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center"><strong>SERVICES REQUESTED </strong></div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center">
        <textarea name="services_requested" cols="60" id="services_requested"></textarea>
      </div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center"><strong>JUSTIFICATION</strong></div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center">
        <textarea name="justification" cols="60" id="justification"></textarea>
      </div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center">
        <input type="submit" value="send">
      </div></td>
    </tr>
  </table>
</form>

    <%
   
            case 2
    ' CDO mail object
    Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
      
      dim msgBody = "The following service request has been submitted: " & vbCrLf & vbCrLf
      msgBody = msgBody & "Date: " & Request.Form("date") & vbCrLf
      msgBody = msgBody & "Requestor: " & Request.Form("requestor") & vbCrLf
      msgBody = msgBody & "Phone number: " & Request.Form("phone_no") & vbCrLf
      msgBody = msgBody & "Services request: " & Request.Form("services_requested") & vbCrLf
      msgBody = msgBody & "Justification: " & Request.Form("justification") & vbCrLf
      'msgBody = msgBody & "Date: " & Request.Form("") & vbCrLf
      

    ' CDO mail setttings
            with objCDOMail
                  .From = Request.Form("requestor")
                  .To = Request.Form("mailList")
                  '.Cc = strCC                        
                  .Subject = "Service Request"
                  .Body = "The following service request has been submitted: " & vbCrLf
                  .MailFormat = 0            ' HTML format       
                  .Send
            end with
      
      ' destroy object, free memory
      set objCDOMail = nothing
   
                   
      Response.Write "Mail Sent to: <b>" & Request.Form("mailList") & "</b>"
    Response.Write ""                                           
          
end select      
   
 
    %>

</body>
</html>


-- end code sendrequest.asp --

0
 

Author Comment

by:contesa
ID: 10859080
Scorpion,

Thank you very much for taking the time to edit my code. My network manager is not in the office today so I can't test the code until tomorrow.

I will give you an update of my results tomorrow.

Thank you again.
0
 

Author Comment

by:contesa
ID: 10860021
Scorpion,

I setup IIS on my personal pc for testing purposes. I wanted to test the code before my network manager returns tomorrow.

I am receiving the following error message:

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/sendrequest.asp, line 106, column 12
dim msgBody = "The following service request has been submitted: " & vbCrLf & vbCrLf
-----------^

I looked at the code and didn't find any misspellings or missing quotes.  What am I missing?  Any ideas?
0
 

Author Comment

by:contesa
ID: 10862180
Scorpion,

I fixed the above code error by splitting up

dim msgBody = "The following service request has been submitted: " & vbCrLf & vbCrLf

into two lines.

dim msgBody
   msgBody = "The following service request has been submitted: " & vbCrLf & vbCrLf

Now, I get the following when clicking send:

Mail sent to:

Nothing else displays --only that line of text. I'm testing the script by entering my own email address.  I haven't received any messages.

I'm using IIS on my personal Win XP pc for testing purposes. I installed and registered cdonts.dll. Am I missing something else?

I appreciate any help you can provide.

Thank you.
0
 
LVL 2

Expert Comment

by:sc0rp10n
ID: 10864403
Hi contesa,

Try to save this the following as an asp file and access it via the browser. Make sure you add your email address before you access it.

This is a simple asp mail using CDONTS. If the mail is sent, then you should see the message "Your mail has been sent. "

Hope this works. Lets start from here, to make sure all is working good.


-- start asp code --

<html>

<head>
<title>Test email</title>
</head>

<body>
<%

Set objMail = Server.CreateObject("CDONTS.NewMail")
objMail.From = "PutYourEmailAddressHere"
objMail.To = "PutYourEmailAddressHere"
objMail.Subject="Test Email"
objMail.Body = "Test Email"
objMail.Send
Set objMail = nothing
%>

<p><strong>Your mail has been sent. </strong></p>

</body>
</html>

-- end asp code --
0
Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

 

Author Comment

by:contesa
ID: 10868358
Scorpion,

The above script does work. I received messages when viewing the page in the browser. But I did notice that it didn't send a message each time I viewed the page, it's intermittent.
0
 

Author Comment

by:contesa
ID: 10868464
Good morning Scorpion,

Looks like my IIS server just needed a little warming up....the messages are coming through about a minute after I view the page.

So the script works!
0
 
LVL 2

Expert Comment

by:sc0rp10n
ID: 10873440
Good morning Contesa,

Well, that means that the mail server/iis + everything else is working perfectly fine. Its just a matter of trying to get the form variables rite.

Try to change the METHOD value from "POST" to "GET", then change "Request.Form" to just "Request".

This should help a bit.
0
 
LVL 2

Expert Comment

by:sc0rp10n
ID: 10873458
btw, "Request" should work, but if it doesn't try "Request.QueryString".
make sure the item is present in the brackets. i.e

Request("requestor")
or
Request.QueryString("requestor")

0
 

Author Comment

by:contesa
ID: 10890358
Hi Scorpion,

It didn't work with either Request or Request.QueryString...I'm still getting the exact same response (Mail sent to:             )

I did change it from post to get as well.

Any other suggestions?

Again, thank you very much  for all of your help.
0
 
LVL 2

Expert Comment

by:sc0rp10n
ID: 10894943
hy contesa,

quick question, does your mail server relay emails. as in the mails that you are sending, do they have internal email addresses.

Also, if you can post your code, i'll have a go at it myself and will let you know. But theoritically, it should've worked as i've used that same code myself a while back.

0
 

Author Comment

by:contesa
ID: 10904805
Hi Scorpion,

Here is the code:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>ITMS Service Request</title>
<%
     response.buffer=true
   
     Func = Request("Func")
         
     if isempty(Func) then
              Func = 1
     end if

    Select case Func
          case 1
    %>
<style type="text/css">
<!--
.style1 {
     color: #000000;
     font-weight: bold;
}
-->
</style>
</head>

<body><form action="sendrequest.asp?func=2" method="get" enctype="multipart/form-data" name="myForm">
  <table width="500" border="1" align="center">
    <tr>
      <td colspan="5"><table width="100%"  border="0" align="center">
          <tr>
            <td colspan="2"><div align="center" class="style1">Information Technology Management &amp; Support<br>
  SERVICE REQUEST </div></td>
          </tr>
          <tr>
            <td width="18%">Request No.</td>
            <td width="82%">&nbsp;</td>
          </tr>
        </table></td>
    </tr>
    <tr>
      <td width="121"><div align="center">DATE</div></td>
      <td width="152"><div align="center">REQUESTOR</div></td>
      <td width="100"><div align="center">BUREAU</div></td>
      <td width="99" colspan="2"><div align="center">PHONE # </div></td>
    </tr>
    <tr>
      <td><div align="center">
        <input name="date" type="text" id="date" size="20" maxlength="20">
      </div></td>
      <td><div align="center">
        <input name="requestor" type="text" id="requestor" size="20" maxlength="30">
      </div></td>
      <td><div align="center">
        <select name="mailList">
          <option value="kathy.coates@njdge.org">ADM</option>
          <option value="dan.kelly@njdge.org">CEB/NJSP</option>
          <option value="paul.kuras@njdge.org">CIU</option>
          <option value="ted.grove">CJ</option>
          <option value="mike.romano@njdge.org">CLS</option>
          <option value="jean.escarpeta@njdge.org">ELS</option>
          <option value="rich.handzo@njdge.org">REB</option>
          <option value="debbie.algor@njdge.org">REC/ID</option>
          <option value="al.white@njdge.org">SILS</option>
          <option value="rich.williamson@njdge.org">TSB</option>
          <option value="willie.johnson@njdge.org">willie.johnson@njdge.org</option>
            <option value="jon.rocque@njdge.org">TEST2</option>
        </select>
      </div></td>
      <td colspan="2"><div align="center">
        <input name="phone_no" type="text" id="phone_no" size="10" maxlength="10">
      </div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center"><strong>SERVICES REQUESTED </strong></div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center">
        <textarea name="services_requested" cols="60" id="services_requested"></textarea>
      </div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center"><strong>JUSTIFICATION</strong></div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center">
        <textarea name="justification" cols="60" id="justification"></textarea>
      </div></td>
    </tr>
    <tr>
      <td colspan="5"><div align="center">
        <input type="submit" value="send">
      </div></td>
    </tr>
  </table>
</form>

    <%
   
          case 2
    ' CDO mail object
    Set objCDOMail = Server.CreateObject("CDONTS.NewMail")
     
     dim msgBody
       msgBody = "The following service request has been submitted: " & vbCrLf & vbCrLf
     msgBody = msgBody & "Date: " & Request.QueryString("date") & vbCrLf
     msgBody = msgBody & "Requestor: " & Request.QueryString("requestor") & vbCrLf
     msgBody = msgBody & "Phone number: " & Request.QueryString("phone_no") & vbCrLf
     msgBody = msgBody & "Services request: " & Request.QueryString("services_requested") & vbCrLf
     msgBody = msgBody & "Justification: " & Request.QueryString("justification") & vbCrLf
     'msgBody = msgBody & "Date: " & Request.Form("") & vbCrLf
     

    ' CDO mail setttings
          with objCDOMail
               .From = Request.QueryString("requestor")
               .To = Request.QueryString("mailList")
               '.Cc = strCC                    
               .Subject = "Service Request"
               .Body = "The following service request has been submitted: " & vbCrLf
               .MailFormat = 0          ' HTML format      
               .Send
          end with
     
     ' destroy object, free memory
     set objCDOMail = nothing
   
                 
     Response.Write "Mail Sent to: <b>" & Request.QueryString("mailList") & "</b>"
    Response.Write ""                                    
         
end select    
   
 
    %>

</body>
</html>


As you can see the last test I ran was with Request.QueryString. I'm not quite sure about your relay emails question. I am testing this on my personal WIN XP pc, I set up IIS on the pc. I haven't changed any of the settings.

Hope this helps....

Again, thank you.
0
 

Author Comment

by:contesa
ID: 10990255
Hi Scorprion,

I want to award you some points for all of your help. I rewrote some of your script and it works now. How do I award the points?
0
 
LVL 2

Expert Comment

by:sc0rp10n
ID: 11004099
hy contesa,

congratulations on solving it. I'm sorry i wasn't at work for the past few days and I couldn't check my mail.

anyhoo, try the following link: http://www.experts-exchange.com/Community_Support/help.jsp#hi68

Basically there will be an accept button near a solution. you should just click that.

sc0rp
0
 

Author Comment

by:contesa
ID: 11004931
Scorpion,

Thanks for getting me started in the right direction. I really appreciate all of your help. On to my next dilemma!
0
 
LVL 2

Expert Comment

by:sc0rp10n
ID: 11024787
thx contesa,

glad to have showed you the way.
0

Featured Post

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

Suggested Solutions

Preface This article introduces an authentication and authorization system for a website.  It is understood by the author and the project contributors that there is no such thing as a "one size fits all" system.  That being said, there is a certa…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

760 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now