Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 13th, 2007, 01:09 PM
Registered User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Attaching a file using FormMail.cgi

I've been trying to figure out how to use the canned tools on my ISPs web site to create an email form. Most of it is a simple form (only text fields and areas) but the gotcha is attaching a file to the created email.

I started out trying to use cgiemail. Despite having found documentation on how to attach a file, it wouldn't accept any "enctype". So I switched to the other option available to me, FormMail.cgi (which is a clone of the original). That's what I've been fighting with for the last two days.

The HTML code follows. Dreamweaver created the Javascript that does the data validation.

I've also noticed that the "from_email" and "from_name" don't seem to be working. I'll really appreciate your help.
David



<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<script language="JavaScript">
<!--
function MM_findObj(n, d) { //v4.0
  var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && document.getElementById) x=document.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
  var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
  for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
    if (val) { nm=val.name; if ((val=val.value)!="") {
      if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
        if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
      } else if (test!='R') {
        if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
        if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
          min=test.substring(8,p); max=test.substring(p+1);
          if (val<min || max<val) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
    } } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
  } if (errors) alert('The following error(s) occurred:\n'+errors);
  document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<h2 align="center">Paper Proposal for
    Rome, Italy, May 22-23, 2007</h2>
<form name="form1" method="post" action="/cgi-sys/FormMail.cgi" enctype="multipart/form-data">

    <input type="hidden" name="recipient" value="david@essentialcoaching.com">
    <input type="hidden" name="from_email" value="auto.sender@essentialcoaching.com">
    <input type="hidden" name="from_name" value="send only address">
    <input type="hidden" name="subject" value="Submission of abstract">

    <h3 align="center">Submitter Information
    </h3>
    <table width="100%" border="0" cellpadding="3" cellspacing="3" name="submit_paper_tbl" align="center">
        <tr>
            <td><i><b>Required
                fields are italicized</b></i></td>
        </tr>
        <tr>
            <td colspan="2">
                <table width="100%" border="0" cellpadding="3" cellspacing="3">
                    <tr>
                        <td>
                            <div align="right"><i>Last
                                Name:</i></div>
                        </td>
                        <td>
                            <input type="text" name="lname">
                        </td>
                        <td>
                            <div align="right"><i>First
                                Name:</i></div>
                        </td>
                        <td>
                            <input type="text" name="fname">
                        </td>
                    </tr>
                    <tr>
                        <td>
                            <div align="right">M.I.:</div>
                        </td>
                        <td>
                            <input type="text" name="midinitial">
                        </td>
                        <td>
                            <div align="right">Title:</div>
                        </td>
                        <td>
                            <input type="text" name="title">
                        </td>
                    </tr>
                </table>
            </td>
        </tr>
        <tr>
            <td valign="top">
                <div align="right"><i>Company:</i></div>
            </td>
            <td valign="top">
                <textarea name="company" cols="75" rows="2"></textarea>
            </td>
        </tr>
        <tr>
            <td valign="top" width="50%">
                <div align="right"><i>Address:</i></div>
            </td>
            <td valign="top">
                <textarea name="address" rows="5" cols="75"></textarea>
            </td>
        </tr>
        <tr>
            <td>
                <div align="right"><i>Phone
                    Number:</i></div>
            </td>
            <td>
                <input type="text" name="phonenum">
            </td>
        </tr>
        <tr>
            <td>
                <div align="right"><i>Primary
                    Email:</i></div>
            </td>
            <td>
                <input type="text" name="email1" size="75">
            </td>
        </tr>
        <tr>
            <td>
                <div align="right">Secondary
                    Email:</div>
            </td>
            <td>
                <input type="text" name="email2" size="75">
            </td>
        </tr>
        <tr>
            <td>
                <div align="right"><i>Attach
                    Abstract (in Microsoft Word format please):</i></div>
            </td>
            <td>
                <input type="file" name="abstract" size="50">
            </td>
        </tr>
        <tr>
            <td>&nbsp;</td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td colspan="2">
                <div align="center">
                    <input type="reset" name="clearform" value="Clear Form">
                    <input type="submit" name="submit" value="Submit Proposal" onClick="MM_validateForm('lname','','R','fname','' ,'R','phonenum','','R','email1','','RisEmail','com pany','','R','address','','R');return document.MM_returnValue">
                </div>
            </td>
        </tr>
    </table>
</form>
<p>&nbsp; </p>
</body>
</html>
 
Old February 14th, 2007, 04:06 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

But what's not working? Is there a problem with validation or the email does not get sent or what?

--

Joe (Microsoft MVP - XML)
 
Old February 14th, 2007, 09:39 AM
Registered User
 
Join Date: Feb 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks for the reply.

Sorry, I thought I had said, but see that I didn't.
There's no attachment. And I've also noticed that the "from_email" and "from_name" don't seem to be having an effect. That is, the data is included in the script but it's not actually setting the information on where the mail appears to be coming from. The text below is an example of an email--followed by the headers.


>>> The email I received:
from_email: auto.sender@tv-2-mobile.com

from_name: TV2Mobile send only address

lname: Kessler

fname: David

company: TV2Mobile
Home office

address: 20 Barberry Road
Lexington, MA
02421

phonenum: 781-863-1140

email1: david@essentialcoaching.com

file-original.htm-key: abstract

file-original.htm: /tmp/cpanel.TMP.p45stpgW886ft1ko

submit: Submit Proposal


>>> The headers:
Return-path: <djkbiz@host2.dedicated4less.com>
Envelope-to: david@essentialcoaching.com
Delivery-date: Tue, 13 Feb 2007 10:06:40 -0500
Received: from djkbiz by host2.dedicated4less.com with local (Exim 4.63)
    (envelope-from <djkbiz@host2.dedicated4less.com>)
    id 1HGzFH-0007V6-Eb
    for david@essentialcoaching.com; Tue, 13 Feb 2007 10:06:40 -0500
To: david@essentialcoaching.com
From: webmaster@host2.dedicated4less.com
Subject: Submission of abstract
Message-Id: <E1HGzFH-0007V6-Eb@host2.dedicated4less.com>
Date: Tue, 13 Feb 2007 10:06:40 -0500





Similar Threads
Thread Thread Starter Forum Replies Last Post
Attaching File with Mail using PHP sankar2chat Beginning PHP 1 September 24th, 2008 05:40 AM
attaching image file Matthew Dreamweaver (all versions) 3 May 25th, 2007 03:04 AM
help! on CGI Error heerajee Pro PHP 0 February 2nd, 2006 05:17 AM
attaching the file stored in databse to an eamil kale_tushar ASP.NET 1.0 and 1.1 Professional 1 January 6th, 2005 05:51 AM
MIME Attaching PDF file jer99 Pro PHP 1 August 18th, 2003 02:31 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.