Link to home
Start Free TrialLog in
Avatar of contesa
contesaFlag for United States of America

asked on

Form Mail

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?
Avatar of monolith_888
monolith_888

=========
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
Avatar of contesa

ASKER

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.
contesa,

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

ASKER

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.

Avatar of contesa

ASKER

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>
ASKER CERTIFIED SOLUTION
Avatar of sc0rp10n
sc0rp10n

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of contesa

ASKER

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.
Avatar of contesa

ASKER

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?
Avatar of contesa

ASKER

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.
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 --
Avatar of contesa

ASKER

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.
Avatar of contesa

ASKER

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!
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.
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")

Avatar of contesa

ASKER

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.
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.

Avatar of contesa

ASKER

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.
Avatar of contesa

ASKER

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?
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: https://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
Avatar of contesa

ASKER

Scorpion,

Thanks for getting me started in the right direction. I really appreciate all of your help. On to my next dilemma!
thx contesa,

glad to have showed you the way.