Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mail a form

Status
Not open for further replies.

jjinx

Programmer
Oct 6, 2002
12
US
I need to be able to have users enter information into a form and then submit it. But I need the information in the form to be e-mailed to me. I there any way to do this.
 
Hi mate,

What server side languages can you use?

There is a mailto: function but it is very unreliable so you are better to process it server side.

Hope this helps

Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
Check with your hosting company. Many of them offer a free script called cgiemail that's very easy to set up and use. There's always a better way...
 
jjinx,

I had this same need, but I wasn't permitted to install anything on the server, so I had to do it all in JavaScript. But bear with me -- this is actually pretty straightforward.

I needed the contents of a bunch of text windows e-mailed to me. This solution required two forms on the same page and one small separate .js file:

First, the "Entry" document:

Code:
<!DOCTYPE html 
     PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
     &quot;[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;>[/URL]

<html xmlns=&quot;[URL unfurl="true"]http://www.w3.org/1999/xhtml&quot;[/URL] xml:lang=&quot;en&quot; lang=&quot;en&quot;>
  <head>
    <meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;></meta>
    <title>Send Out The Data</title>
    <link rel=&quot;stylesheet&quot; href=&quot;Style.css&quot; type=&quot;text/css&quot;></link>
    <script src=&quot;sample.js&quot; type=&quot;text/javascript&quot;></script>
  </head>
  <body>
  <h3>Submissions Form</h3>
  <form name=&quot;SubmissionForm&quot; action=&quot;mailto:HungryMan@DonnerParty.com&quot; enctype=&quot;multipart/form-data&quot;>
    <table class=&quot;Fatscope&quot;>
      <tr>
        <td class=&quot;DescriptorCell&quot;>Function Name:</td>
        <td class=&quot;ContentCell&quot;><input type=&quot;text&quot; size=&quot;100&quot; id=&quot;FunctionName&quot;></input></td>
      </tr>
      <tr>
        <td class=&quot;DescriptorCell&quot;>Module which contains Function:</td>
        <td class=&quot;ContentCell&quot;><input type=&quot;text&quot; size=&quot;100&quot; id=&quot;ModuleName&quot;></input></td>
      </tr>
      <tr>
        <td class=&quot;DescriptorCell&quot;>Module Location:</td>
        <td class=&quot;ContentCell&quot;><input type=&quot;text&quot; size=&quot;100&quot; id=&quot;ModuleLocation&quot;></input></td>
      </tr>
      <tr>
        <td class=&quot;DescriptorCell&quot;>Function Description:</td>
        <td class=&quot;ContentCell&quot;><textarea cols=&quot;75&quot; rows=&quot;5&quot; id=&quot;FunctionDescription&quot;></textarea></td>
      </tr>
      <tr>
        <td class=&quot;DescriptorCell&quot;>Function Parameters:</td>
        <td class=&quot;ContentCell&quot;><input type=&quot;text&quot; size=&quot;100&quot; id=&quot;FunctionParameters&quot;></input></td>
      </tr>
      <tr>
        <td class=&quot;DescriptorCell&quot;>Function Example Call:</td>
        <td class=&quot;ContentCell&quot;><input type=&quot;text&quot; size=&quot;100&quot; id=&quot;FunctionExample&quot;></input></td>
      </tr>
      <tr>
        <td class=&quot;DescriptorCell&quot;>Programmer Name:</td>
        <td class=&quot;ContentCell&quot;><input type=&quot;text&quot; size=&quot;100&quot; id=&quot;ProgrammerName&quot;></input></td>
      </tr>
    </table>
    <p class=&quot;CenteredContent&quot;><input type=&quot;reset&quot; value=&quot;Clear All Entries&quot; class=&quot;PDButton&quot;></input></p>
  </form>

  <form name=&quot;ProxyForm&quot; enctype=&quot;text/plain&quot; method=&quot;post&quot; action =&quot;mailto:HungryMan@DonnerParty.com?subject=Reuseable Code Library Submission&quot; onsubmit=&quot;update_message_body();return true;&quot;>
    <p class=&quot;CenteredContent&quot;><input type=&quot;submit&quot; value=&quot;Submit New Function&quot; class=&quot;PDButton&quot;></input></p>
    <input type=&quot;hidden&quot; id=&quot;MessageBody&quot; name=&quot;MessageBody&quot;></input>
  </form>
  </body>
</html>

Obviously, this uses an external stylesheet called &quot;Style.css&quot;, which you can tell from the class calls, but don't let that bother you -- it's just things like background colors, etc. Also, it should be obvious that I trimmed away a bunch of content that is proprietary, but again, it shouldn't be a problem.

Here's the external JavaScript file, which should be saved as &quot;sample.js&quot;:

Code:
    function update_message_body()
      // This function composes an e-mail message using the contents of 
      // another form on the same page.
      {
        var FunctionName = document.SubmissionForm.FunctionName.value;
        var ModuleName = document.SubmissionForm.ModuleName.value;
        var ModuleLocation = document.SubmissionForm.ModuleLocation.value;
        var FunctionDescription = document.SubmissionForm.FunctionDescription.value;
        var FunctionParameters = document.SubmissionForm.FunctionParameters.value;
        var FunctionExample = document.SubmissionForm.FunctionExample.value;
        var ProgrammerName = document.SubmissionForm.ProgrammerName.value;
        var CurrentDate = new Date();

        document.ProxyForm.MessageBody.value = &quot;\n\n&quot; + &quot;-= Start of Message =-&quot; + &quot;\n\n&quot;
                                                + &quot;Reuseable Code Library Submission&quot; + &quot;\n\n&quot;
                                                + &quot;Time received: &quot; + CurrentDate + &quot;\n\n&quot;
                                                + &quot;Function Name: &quot; + FunctionName + &quot;\n\n&quot;
                                                + &quot;Module Name: &quot; + ModuleName + &quot;\n\n&quot;
                                                + &quot;Module Location: &quot; + ModuleLocation + &quot;\n\n&quot;
                                                + &quot;Function Description: &quot; + FunctionDescription + &quot;\n\n&quot;
                                                + &quot;Function Parameters: &quot; + FunctionParameters + &quot;\n\n&quot;
                                                + &quot;Function Example Call: &quot; + FunctionExample + &quot;\n\n&quot;
                                                + &quot;Submitted by: &quot; + ProgrammerName + &quot;\n\n&quot; + &quot;-= End of Message =-&quot;;
        return true;
      }

Sends all that junk in e-mail, neat as you please.

The tiniest caveat is that the browser -- depending upon your security settings -- pops up a warning that you are about to send e-mail via the web page.

I have not tested this in anything other than IE, as this client insisted on using only IE on all their machines.

Good luck!

Edward &quot;Do not read this sentence.&quot;
 
Hi guys,

Just a little warning to anyone deciding to use the mailto method.

If a client does not have a default mail client installed, they will not be able to send mail from a mailto: link.

The biggest problem I can see with this method is that a lot of people do not like providing their e-mail address through forms of this type.

Personally, I use many different e-mail accounts (Personal and a few business)and I might want to send the e-mail from a certain account. This is not possible with mailto: as it only launches the default client.

Overall, mailto: links are very commonly thought of as unproffesional.

Take a look at
Hope this helps Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
Well, I suppose it depends on one's definition of &quot;professional&quot;. 8)

In my case, I was instructed to not use any server-side programming. The environment is controlled (all on an internal network), every terminal has a mail client, and no one is allowed to &quot;hide&quot; their e-mail addresses, nor would they want to.

When I do this sort of thing for the WWW, I usually use Perl and sendmail running on the server.

But this solution didn't require knowing anything about the server.

If jjinx knows that Perl is accessible on the server, then I'm sure someone (or me) will post a terrific solution that uses Perl.

Cheers,

Edward &quot;Do not read this sentence.&quot;
 
Hi mate,

My post was not aimed at you or anyone else, it was just adding a caution for people thinking of using this method.

In my personal opinion, there is no need to use a mailto: link other than for a simple link. When you start to require the addition of body text, a subject or bcc, etc then you should use a server side script to process the information.

If your current server does not offer you any way to send mail from your site, upgrade to one that is inline with current technologies. I have yet to see any decent host that does not either offer a generic script or the support for a language that you can use to create your own.

Having said all that, if you are producing this, or anything else for an intranet or any other tightly controlled environment then a lot of the common design problems like this one don't matter.

Hope this helps Wullie


The pessimist complains about the wind. The optimist expects it to change.
The leader adjusts the sails. - John Maxwell
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top