Question

Need CGI EMAIL help for a newbie trying to create a simple web form

Asked by: rngrfan

I am attempting to create a simple form on a web site for my brother that will email some customer information.

Heres what I have so far

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<head>

<FORM METHOD="POST"
ACTION="http://ankerpools/public_html/cgi-bin/simpleform.txt">

Your e-mail address: <INPUT NAME="email"><p>
Your name: <INPUT NAME="yourname"><p>
<INPUT TYPE="submit" value="Send e-mail">
</FORM>
     
 
</BODY>
</HTML>

I copied the action line from some MIT manual that I found and tried to convert to my brothers info.  Not real sure I did that right.

I also created the simpleform.txt file which I uploaded to the public_html/cgi-bin folder on the web server.  I was just guessing this was the right spot but not real sure.

The simpleform.txt looks like this

To:test@ankerpools.com                          HEADER LINES
Subject: Two Questions
                                                 
What is your email?              [email]          BODY
What is your name?             [yourname]          


Can someone please help me and tell me what I am doing wrong.   Don't know I if is extremely difficult for you but it is for me so 500pts.

Thanks in advance for your help and patience with me on this.

This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.

Subscribe now for full access to Experts Exchange and get

Instant Access to this Solution

  • Plus...
  • 30 Day FREE access, no risk, no obligation
  • Collaborate with the world's top tech experts
  • Unlimited access to our exclusive solution database
  • Never be left without tech help again

Subscribe Now

Asked On
2005-04-24 at 09:24:57ID21400477
Tags

email_binary

,

my

Topic

CGI Scripting

Participating Experts
3
Points
500
Comments
20

Trusted by hundreds of thousands everyday for fast, accurate and reliable tech support.

  • "The time we save is the biggest benefit of Experts Exchange to Warner Bros. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange." Mike Kapnisakis, Warner Bros.
  • "Our team likes having a resource that is more secure than just using Google and most experts using this service really know their stuff. It's nice to look here first versus using Google." Dayna Sellner, Lockheed Martin
  • "Anytime that I've been stumped with a problem, 9 out of 10 times Experts Exchange has either the accepted solution or an open discussion of the potential solution to the problem." Kenny Red, eBay Inc.

See what Experts Exchange can do for you.

Got a question?

We've got the answer.

Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.

Screenshot of Experts Exchange Knowledgebase

Need individual assistance?

Our experts are ready to help.

If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.

Screenshot of Experts Exchange Knowledgebase

Want to learn from the best?

Read articles from industry experts.

Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.

Screenshot of an Article

Working on a long term project?

Store your work and research.

Save solutions to your questions, answers you’ve discovered through searching plus helpful articles in your personal knowledgebase for easy future access.

Screenshot of Experts Exchange Knowledgebase

Access the answers to your technology questions today.

Subscribe Now

30-day free trial. Register in 60 seconds.

What Makes Experts Exchange Unique?

Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Trusted by the world's most respected brands.

image of each brand's logo

Faithfully serving IT professionals since 1996.

Experts Exchange Logo

Try it out and discover for yourself.

Subscribe Now

30-day free trial. Register in 60 seconds.

Related Solutions

  1. Newbie in CGI programming !
    Can anybody show me website that has a lot resource of CGI ? Kinds of resource: - how to make a "hello world" cgi - tutorial for newbie - how to create random access file - sample code - etc regards herman
  2. Javascript to CGI
    I need to change this script into cgi language. I need it to store it in a variable like $shipping. ---------------------------------------------- <SCRIPT> <!-- function calculateShipping() { var gtotal = eval( document.myForm.amount.value ); //this will ...
  3. CGI not working with Apache
    Hi, I am trying to execute some CGI scripts on my Apache HTTP server. The server is working fine, except CGI scripts do not run. I keep on receiving the following error: ---------------------------------------- Server error! The server encountered an internal e...
  4. CGI and Javascript
    Hi Can anyone tell me if its possible to pass javascript variables from a form to a cgi script and if so could you post an simple example of how to do this. Thanks
  5. CGI-BIN Problem
    Hopefully i'm posting this in the right spot. Anyway i'm moving a website from 1 server to another. I've coppied all the files from one to another in the same spots. The site works fine w/ the exception of some cgi-bin stuff. Here is what i have: In a page i have a lin...

Free Tech Articles

  1. WARNING: 5 Reasons why you should NEVER fix a computer for free.
    It is in our nature to love the puzzle. We are obsessed. The lot of us. We love puzzles. We love the challenge. We thrive on finding the answer. We hate disarray. It bothers us deep in our soul. W...
  2. SCCM OSD Basic troubleshooting
    SCCM 2007 OSD is a fantastic way to deploy operating systems, however, like most things SCCM issues can sometimes be difficult to resolve due to the sheer volume of logs to sift through and the dispe...
  3. Migrate Small Business Server 2003 to Exchange 2010 and Windows 2008 R2
    This guide is intended to provide step by step instructions on how to migrate from Small Business Server 2003 to Windows 2008 R2 with Exchange 2010. For this migration to work you will need the fo...
  4. Create a Win7 Gadget
    This article shows you how to create a simple "Gadget" -- a sort of mini-application supported by Windows 7 and Vista. Gadgets can be dropped anywhere on the desktop to provide instant information, ...
  5. Outlook continually prompting for username and password
    There have been a lot of questions recently regarding Outlook prompting for a username and password whilst using Exchange 2007. There are a few reasons why this would happen and I will try to cover t...
  6. Backup Exchange 2010 Information Store using Windows Backup
    There seems to be quite a lot of confusion around the ability to backup Exchange 2010 using the built in Windows Backup feature. This stems from the omission of this feature prior to Exchange 2007 s...

Cloud Class Webinars

  1. Avoiding Bugs in Microsoft Access
    Alison Balter takes and in-depth look at avoiding bugs in Access. In this webinar you will learn about using the immediate window to debug your applications, invoking the debugger, using breakpoints to troubleshoot, stepping through code, setting the next statement to execute, ...
  2. Top 10 Best New Features in Visio 2010
    Scott Helmers gives live demonstrations of the top 10 new features in Visio 2010. This webinar will teach you how to create compelling diagrams by adding shapes to the page with a single click, linking the shapes in a diagram to data in Excel (or SQL Server, or SharePoint), ...
  3. IT Consultant Business Secrets Revealed
    Michael Munger, Experts Exchange tech pro and IT consultant, pulls back the curtain on his very successful businesses and answers question on every IT consultant and business owner should know about. He shares secrets on what he did to solve the 5 most common problems in IT, ...
  4. Disaster Recovery and Business Continuity
    Quest CTO, Mike Billon, gives an overview of the steps involved in building a dunamic disaster recovery plan. Through case studies and an examination of software/hardware tooles for monitoring and testing, you'll gain a better understandin of where you are, where you want ...
  5. Organize Your Visio Diagrams with Containers and Lists
    Scott Helmers uses cross functional flowcharts, wireframe diagrams, data graphic legends and seating charts to teach you: how to ustilize all three new structured diagram components in Visio 2010, the best practices for organizeing shapes in previous version of Visio, how to organize ...
  6. How to Us Objects, Properties, Events and Methods in Microsoft Access
    Alison Dalter gives an in-depbth look at objects, properties, events and methods in Microsoft Access. In this webinar you will learn about using the object browser, referring to objects, working with properties and methods, working with object variables, understanding the ...

Join the Community

Give a Little. Get a Lot.

Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.

Join the Community

Answers

 

by: ahoffmannPosted on 2005-04-25 at 00:17:59ID: 13856564

the ACTION= attribute need to point to a CGI script (or any other active page on your web server) and not to a simple text file.
This script then needs to parse your form data and send the mail.
Your postes simpleform.txt looks more like an example how the generated mail might look like.

 

by: divtPosted on 2005-04-25 at 04:36:40ID: 13857515

rngrfan,

What you need is a CGI and a web form working together.
Please find below links that contain step-by-step instructions:

A Simple CGI Email Handler
http://www.boutell.com/email/

If you are not comfortable setting up your own CGI, check out this one:

Free Feedback form
http://freedback.com/

Hope this helps.

 

by: rngrfanPosted on 2005-04-25 at 09:43:59ID: 13860092

I need some help determining what the correct action needs to be first and then what to change the 2 line in the cgi email script.

When I log onto WS FTP to upload web pages I see that there is a cgiemail (binary file) in the /public_html/cgi-bin.  Is this the spot where my action needs to point?  If so should it read

<FORM METHOD="POST"
ACTION="http://ankerpools.com/cgi-bin/cgiemail">


 

by: rngrfanPosted on 2005-04-25 at 10:45:09ID: 13860555

OK I think I have the action part correct at http://ankerpools.com/cgi-bin/email.cgi"

Now for the changes that need to be made to the cgi script I am really confused.

Divt pointed me to the above script which I downloaded.


Configuring email.cgi
Just after the copyright notice in email.c, there are two very important definitions you just configure. The first defines the location of the sendmail utility on your system. The default setting works for many systems; however if email.cgi does not send email for you and displays no error message, it is highly likely that sendmail is located in a different place on your system, perhaps /sbin/sendmail or /usr/bin/sendmail. If you are not using a Unix-based server, you do not have sendmail and probably cannot use this script.




The second setting defines the location of your email configuration file, which you will want to set to the following:

my $emailConfPath = "/home/www/conf/email.conf"

Where you must replace "/home/www/conf" with the directory where you have decided to keep your email configuration file. Your email configuration file contains a list of allowed email recipients and the pages to which users should be redirected after email is sent to those recipients, on alternating lines. You can create this file with a text editor such as notepad or pico.
The second (new in version 2.1) defines the location of the email binary:

#define EMAIL_BINARY "/bin/mail"

If this is not the location of your email binary, change this #define appropriately. (Typing 'which mail' at your shell prompt may help you discover the correct location for your system.)

 

by: rngrfanPosted on 2005-04-25 at 11:15:36ID: 13860814

Please ignore the above comment.  Hit submit by accident.

OK I think I have the action part correct at http://ankerpools.com/cgi-bin/email.cgi"

+++++Now for the changes that need to be made to the cgi script I am really confused.

+++++Divt pointed me to the above script which I downloaded.


Configuring email.cgi
Just after the copyright notice in email.c, there are two very important definitions you just configure. The first defines the location of the sendmail utility on your system. The default setting works for many systems; however if email.cgi does not send email for you and displays no error message, it is highly likely that sendmail is located in a different place on your system, perhaps /sbin/sendmail or /usr/bin/sendmail. If you are not using a Unix-based server, you do not have sendmail and probably cannot use this script.

+++++MY SENDMAIL IS /USR/SBIN?SENDMAIL which looks to me to be the default


The second setting defines the location of your email configuration file, which you will want to set to the following:

my $emailConfPath = "/home/www/conf/email.conf"

+++++I have created an email.conf file and place it in  /public_html/conf and changed my email.cgi file to read    

+++++my $emailConfPath = "/public_html/conf/email.conf


The second (new in version 2.1) defines the location of the email binary:

#define EMAIL_BINARY "/bin/mail"

If this is not the location of your email binary, change this #define appropriately. (Typing 'which mail' at your shell prompt may help you discover the correct location for your system.)

+++++Is this the file in the /public_html/cgi-bin named cgiemail that is a binary file?

+++++I rent space through ACENET and some general serverinformation
 Server name xxxxxxxxxxxxxxxx
  WWW directory xxxxxxxxxxxxxxxxxxxxx
  Root directory xxxxxxxxxxxxxxxxxxxxxxx
  Path to PERL /usr/bin/perl  
  Perl modules Click to view  
  Path to sendmail /usr/sbin/sendmail  
  Apache version 1.3.33 (Unix)  
  MySQL version 4.0.23-standard  
  PHP version 4.3.10  
  PHP info Click to view  
  PERL version 5.8.4

+++++Shell prompt?  Is there something similar on windows that I can use?


Hope this makes some sense to someone because its a little foggy to me.

 

by: ahoffmannPosted on 2005-04-25 at 14:30:49ID: 13862341

> #define EMAIL_BINARY "/bin/mail"
what's the filename wher you find this?

> Is this the file in the /public_html/cgi-bin named cgiemail that is a binary file?
do you mean that you have a file    /public_html/cgi-bin/cgiemail  ?
then please post the result of:
  file  /public_html/cgi-bin/cgiemail

> +++++Shell prompt?
what does this mean?

 rngrfan, if you're not used to all the things you have to do, please post verbatim what you've done, and what the result is you get. Posting a textual description of what you think it could/should be does not help much ('cause experts might think in another way;-)

 

by: rngrfanPosted on 2005-04-25 at 19:05:20ID: 13863574

ahoffmann sorry if this was unclear to you.  I was following instructions posted by divt at http://www.boutell.com/email/

my comment have +++++++ infront of them

the other comments I am having problem with come from the site above.  

If you need any info please let me know and I will post asap.


 

by: rngrfanPosted on 2005-05-21 at 17:22:11ID: 14053493

Im still lost and havent receive and answer sorry.

 

by: perlpengoPosted on 2005-05-23 at 04:23:28ID: 14059208

You just have to copy and paste the code to two files.
One named "my_sendmail.html" (which you can put into your DocumentRoot folder on your server),
and the other "my_sendmail.cgi" (which you have to put it into the cgi-bin folder into your server).

There is a chance to have to change something in your 'my_sendmail.html' file.
At the line where the  <form action="/cgi-bin/my_sendmail.cgi" method="POST"> is ,
you might need to change the path like this
<form action="/public_html/cgi-bin/my_sendmail.cgi" method="POST">
But first try it as it is.

First of all lets make your form look a little better

my_sendmail.html
---------------------------------
<html>
   <head>
      <title>A form to send mail</titlte>
   </head>
   <body>
   <p align="center"><b><h1>Send Email</h1></b>
      <br>
      Please fill all the fields
      <br><br>    
   </p>
   <table align=center width="80%" border="0" cellspacing="0">
      <form action="/cgi-bin/my_sendmail.cgi" method="POST">
            <tr>
             <td align=left>Your name: </td>
             <td align=left><input type="text" name="name"></td>
          </tr>
          
          <tr>
             <td align=left>Your e-mail address: </td>
             <td align=left><input type="text" name="sender"></td>
          </tr>
          
          <tr>
             <td align=left>Recipient's email: </td>
             <td align=left><input type="text" name="recipient"></td>
          </tr>

          <tr>
             <td align=left>Subject: </td>
             <td align=left><input type="text" name="subject"></td>
          </tr>
                   
          <tr>
             <td align=left>Message: </td>
             <td align=left><textarea name="message" cols=40 rows=20></textarea></td>
          </tr>
   </table>
   <p align="center"><input type="submit" name="send" value="Send"></p>
     </FORM>
   </body>
</html>



Now lets make your cgi file which will do a little 'kung fu' to do what you want


my_sendmail.pl
-------------------------
#!/usr/bin/perl -w
use strict;
use CGI;

my $query = new CGI;

my $name = $query->param('name');
my $sender = $query->param('sender');
my $recipient = $query->param('recipient');
my $subject = $query->param('subject');
my $message = $query->param('message');

if (($name eq "") || ($sender eq "") || ($message eq "") || ($recipient eq ""))
{
      &error("Email Rejected",
            "Please fill out all fields provided. Back up to the " .
            "previous page to try again.");
}

open (MAIL, "| /usr/sbin/sendmail -t");
print MAIL <<MyMail;
To: $recipient
From: $name <$sender>
Subject: $subject

$message;
.
MyMail
close MAIL;


sub error {
    # Output a valid HTML page as an error message
    my($title, $content) = @_;
    print $query->header;
#don't try to change the spaces from this point and after cause it might not find the end of EOM.
#leave it like this.
print <<EOM;
<html>
<head>
<title>$title</title>
</head>
<body>
<h1 align="center">$title</h1>
<p align=center>
$content
</p>
</body>
</html>

.
EOM

exit 0;
}

It could be more complicated (as to check for mispelled addresses, to look for dangerous code in the place of the texts, and others) but i think your brother doesn't care that much.
If though you like it more secure just tell me about it.

I hope this is what you want. Free to ask any questions if you like.

The error subroutine is taken from the email.cgi that is outthere as divt mentioned

 

by: perlpengoPosted on 2005-05-23 at 04:27:16ID: 14059235

sorry, don't save the file like this

my_sendmail.pl
-------------------------
#!/usr/bin/perl -w
...........................
..................


save it like this

my_sendmail.cgi
-------------------------
#!/usr/bin/perl -w
...............
........................

sorry about that, it was a typo. Instead of .cgi i wrote .pl

 

by: rngrfanPosted on 2005-05-23 at 08:25:09ID: 14060987

Thanks for responding since I havent heard from anyone in a while.

Well I tried your suggestions and dont think I have ever gotten this far so I know I am on the right track.

This is the error message I received:

""Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@ankerpools.com and inform them of the time the error occurred, and anything you might have done that may have caused the error.

More information about this error may be available in the server error log.


Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.

--------------------------------------------------------------------------------
Apache/1.3.33 Server at www.ankerpools.com Port 80""


I tried the suggestion the other way (<form action="/public_html/cgi-bin/my_sendmail.cgi" method="POST">) but I got page not found error.

There was one thing I am not sure I did right.  When you said

"save it like this

my_sendmail.cgi
-------------------------
#!/usr/bin/perl -w"

I copied your text to a notepad from

#!/usr/bin/perl -w
use strict;
use CGI;

all the way down to

</body>
</html>

.
EOM

exit 0;
}


Was that correct?  Also I saved it to the cgi-bin but dont understand the " #!/usr/bin/perl -w " part.



 

by: perlpengoPosted on 2005-05-23 at 23:32:30ID: 14065933

You did good to paste the code from
#!/usr/bin/perl -w
to
exit 0;
}

the first line is the shebang line, which tells where the executable perl is.
in most linux system's it is in /usr/bin folder, others have it in /usr/local/perl/bin, others somewhere else.
Sorry i didn't mention anything about it, i thought you knew some stuff about perl.
So you have to change it to whatever the path to perl executable is on your server.
The '-w' is just for enabling perl warnings (if something is not spelled corectly, or something obvious is mising, etc)

You have to know though that we haven't made any page to tell you "Ok mail sent", or whatever. It will show you a blank page when it is done.
To do that just put this line
print $query->redirect('http://www.ankerpools.com');       #(or inside the link just put the link to your 'Thank you, Ok: mail send' page that you will make!)
after the line
close MAIL;

this will also fix your problem. The problem occured because we didn't place header to the file, only to the error page.
so now with the redirection that we are making you don't need any so this one line will fix it.
Unless there is something in your server that will not let the script work properly.
Tell me if it works.
If it doesn't then go to '/whatever/the/path/to/logs/error_log' file and show me the errors you got.

 

by: rngrfanPosted on 2005-05-24 at 06:33:08ID: 14068072

I looked at Acenet cPanel and it says Path to PERL is /usr/bin/perl so I take it that your original is right.  I added the line in the my_sendmail.cgi but got the same error message as before.

http://www.ankerpools.com/my_sendmail.html changes pages to http://www.ankerpools.com/cgi-bin/my_sendmail.cgi

Error Logs

[2005-05-24 09:26:05]: error: file has no execute permission: (/home/danker/public_html/cgi-bin/my_sendmail.cgi)
[2005-05-24 09:24:43]: error: file has no execute permission: (/home/danker/public_html/cgi-bin/my_sendmail.cgi)
[Tue May 24 09:26:05 2005] [error] [client 69.40.38.26] File does not exist: /home/danker/public_html/500.shtml
[Tue May 24 09:26:05 2005] [error] [client 69.40.38.26] Premature end of script headers: /home/danker/public_html/cgi-bin/my_sendmail.cgi
[Tue May 24 09:24:43 2005] [error] [client 69.40.38.26] File does not exist: /home/danker/public_html/500.shtml
[Tue May 24 09:24:43 2005] [error] [client 69.40.38.26] Premature end of script headers: /home/danker/public_html/cgi-bin/my_sendmail.cgi

 

by: perlpengoPosted on 2005-05-25 at 03:12:30ID: 14075862

Did you add the line i told you
.................
.......................
$message;
.
MyMail
close MAIL;
print $query->redirect('http://www.ankerpools.com');  
sub error {
    # Output a valid HTML page as an error message
    my($title, $content) = @_;
...............
........................


or
       print $query->redirect('http://www.ankerpools.com/my_thankyou_page.html');  




To get rid of the two first errors

           open shell (command prompt), and type

                 cd /path/to/public_html/cgi-bin

         and afetr you are in this folder

                 chmod a+x my_sendmail.cgi


now there are two erros that are saying about a file 500.shtml
did you add a file like that anywhere in the code?

 

by: ahoffmannPosted on 2005-05-29 at 00:21:54ID: 14103906

> I copied your text to a notepad from
do you mean notpad.exe on M$ systems?
then you most likely produced the wrong format for a UNIX system, or did you convert it it to UNIX fomat on the server?

> [2005-05-24 09:26:05]: error: file has no execute permission: (/home/danker/public_html/cgi-bin/my_sendmail.cgi)
you need to do a
   chmod 550 my_sendmail.cgi

> [Tue May 24 09:26:05 2005] [error] [client 69.40.38.26] File does not exist: /home/danker/public_html/500.shtml
this is a configuration error of your server, not related to this cgi, you can ignore it for now

> [Tue May 24 09:26:05 2005] [error] [client 69.40.38.26] Premature end of script headers: /home/danker/public_html/cgi-bin/my_sendmail.cgi
see my comment above about notepad.exe

 

by: rngrfanPosted on 2005-05-29 at 08:51:25ID: 14104921

yes I used notepad on xp os.  is there a way to convert it to unix.  Only options i know i have to create are notepad, wordpad, word 2003, dreamweaver, adode.

 

by: ahoffmannPosted on 2005-05-29 at 12:30:23ID: 14105382

you need to use UNIX format, means no carriage returns just new lines
either your editor can do this, or you need to convert after you've transfered to the UNIX box. Common tools for that are named dos2unix, dos2ux, dosread, to_unix, fromdos, or you can use perl, sed or vi

20120131-EE-VQP-002

3 Ways to Join

30-Day Free Trial

The Experts

98% positive feedback on 31,087 answers since March 2000. angeliii is a Microsoft Most Valuable Professional for his work with MS SQL Server & Develoment.

He has also proven his knowledge of Visual Basic Programming, PHP Scripting and Oracle Databases.

The Experts

97% positive feedback on 10,752 answers since July 2000. lrmoore has more than 18 years experience in the networking industry.

The six-time Mircosoft MVPs specialties include firewalls, virtual private networking, and network management.

Testimonials

"...and excellent source for support... Kind of like having your very own IT dept." Electriciansnet

Testimonials

"I was apprehensive at signing up at first. However... it has already made my life as an IT administrator much easier." JaCrews

Testimonials

"WOW! You guys have great, active, and knowledgeable people on here." moore50

Business Clients

Business Clients

In the Press

"If you’ve got a question... Experts Exchange can supply an answer.”

In the Press

"...an invaluable aid for both IT professionals and those who require tech support."

In the Press

"where IT professionals provide quick answers on just about any topic"

Business Account Plans

Loading Advertisement...