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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Why won't this mailer work

Status
Not open for further replies.

jeffsurfs

MIS
Aug 9, 2001
19
US
It keeps saying it can't find page in browser.I've tried changing up the file extension. The only thing I can think of is the reference to the mail program does not point to anywhere on my site. I have a couple of other programs that may work. If anyone could look at them and thinks they could help please let me know. I could send you the other scripts for a look.
Thanks


email.cgi
#!/usr/bin/perl


%postInputs = readPostInput();

open (MAIL, "|/usr/sbin/sendmail -t") || return 0;


select (MAIL);
print<<&quot;EOF&quot;;
To: JeffJ\ @wayne-ent.com
From: $postInputs{ 'email' }
Subject: Message Board Reply

Email Registration
Name: $postInputs{ 'TheName' }
Email: $postInputs{ 'Email' }
Company Name: $postInputs{ 'Company'}
Address: $postInputs{ 'address' }
Phone: $postInputs{ 'Number' }
Contact: $postInputs{ 'Contact' }
Info: $postInputs{ 'Info' }


EOF

close(MAIL);
select(STDOUT);
printThankYou();

sub readPostInput(){
my(%searchField, $buffer, $pair, @pairs);
if($ENV{ 'REQUEST_METHOD'} eq 'POST'){
read(STDIN, $buffer, $ENV{ 'CONTENT_LENGTH'} );
@pairs = split(/&/, $buffer);
foreach $pair (@pairs){
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])
/pack(&quot;C&quot;, hex($1))/eg;
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])
/pack(&quot;C&quot;, hex($1))/eg;
$searchField{ $name} = $value;
}
}
return (%searchField);
}

sub printThankYou(){
print<<&quot;EOF&quot;;
Content-Type: text/html

<HEAD>
<TITLE>THANK YOU FOR REGISTERING!</TITLE>
<META HTTP-EQUIV=&quot;Content-Type&quot; CONTENT=&quot;document&quot;>
</HEAD>
<BODY>
<TABLE CELLSPACING=2 CELLPADDING=2 border=0 width=600>
<TR>
<BR>
<CENTER>
<FONT SIZE=+3><B>Thank You</b> </font></center><BR><BR>
<CENTER><B> <FONT SIZE=+1>
<P>Thank you $postInputs{ 'Name' } for regisering <BR>
</FONT></B><CENTER>
</TD>
</TR>
</TABLE>

</BODY>
</HTML>

EOF
}
 
It sounds like you are having trouble hitting the file at all.
Are you sure you are saving the file into a valid CGI dir?
Can you get a very simple CGI to work?

try this,
#!/usr/bin/perl
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<HTML><HEAD><TITLE>Simple CGI</TITLE></HEAD>\n&quot;;
print &quot;<BODY>A very simple CGI</BODY></HTML>\n&quot;;


You should be able to save that into your cgi-bin, chmod +x, dos2unix (if needed), and hit it from a browser. Once that works, go back to your email app and give us a verbatim description of the error statement you get.

HTH Please use descriptive titles and check the FAQs.
And, beware the evil typo.
 
I put the sample in my cgi-bin and it wouldn't work. Do I have to chmod before I put it in there? Are these stupid questions I am asking?
 
When you upload (ftp) a piece of perl code onto a Unix server to run as a CGI, you must:
0 - put the code in a valid CGI dir - identified by your ISP
1 - if transfering from a win box, convert the line endings to unix flavor. Most gui ftp clients will do this for you.
2 - once the file is on the unix server,
chmod +x filename
Again, most gui ftp client will also do this, if you ask it to.

Please take a look at faq452-653. It covers this situation. If it does not make sense to you, please post your questions and we'll go from there.

HTH Please use descriptive titles and check the FAQs.
And, beware the evil typo.
 
I tried putting the file in the same folder as exising programs and it still won't work. I have saved it with a cgi and pl extension to no avail.
 
OK, let me get a feel for the landscape here.

What OS are you writing the code on?
What OS are you running the code on (what OS is your ISP running)?
What web server software is your ISP running (Apache, IIS, other?)?
How are you moving the file from your local box to your ISP's server?
Do you have telnet access to the server that the code is running on? Please use descriptive titles and check the FAQs.
And, beware the evil typo.
 
I'm running Windows and the server is Apache. I'm using FTP to transfer to the server. I do have telnet access.
 
I am going to start at the beginning so forgive me if I cover some pretty basic stuff.
You did not specify the OS your ISP is running. I will assume it is a UNIX variant.


ISSUE 1: Line Endings
You are writing your code on a Windows box and trying to run it on a UNIX box.
Win and UNIX line ending are different. Win uses a carriage return and a new line.
Unix uses only a new line. Consequently, you MUST convert the Win file to the UNIX
flavor before it will run on the Unix box.

RESOLUTION:
Some text editors will do that on the Win side. Notepad and WinWord will not.
UltraEdit and TextPad will. If your text editor will convert to Unix line endings,
you can do it on the PC immediately prior to ftp'ing the file to the UNIX box.
- or -
You can put the Win flavored file on the unix box and telnet to the Unix box and use
'dos2unix' to convert it there.

Oh yeah, make sure you are saving the code as plain ascii text.

ISSUE 2: Execute Permissions
Unix OS's have a set of permissions that identify whether or not a file is executable.
In the windows world, that is determined by looking at the file extension (.exe, .bat).

RESOLUTION:
Once the file is on the Unix box, telnet there and 'chmod +x your_code.cgi'. That will set the execute bits for your code.

ISSUE 3: Perl executable path
When you run a prog on your Win PC, your PC determines how to run the program by the file extension. If it is a '.pl' and that extension has been registered on your
system as a Perl file, then your system knows to use perl.exe to run/open the file.
This is similar to double-clicking a '.xls' file. You PC knows to use Excel to open
the file. This is often confusing because most Perl scripts have a first line that
points to the location of Perl on the system. Well, for windows that is not necessary. (except - Apache on Win OS's does use the first line).
However, in unix land, the first line of the code MUST point at the Perl installation
on the unix box. Otherwise, the unix OS has no idea how to run the code.

RESOLUTION:
Edit the first line of your code to point at the Perl interpreter on the UNIX system.
It usually looks something like,
#!/usr/bin/perl
- or -
#!/usr/local/bin/perl

If you don't know where it is, check with your ISP.

ISSUE 4: CGI dir?
You must put your CGI code in a dir on the unix box that the Web server thinks is a
legal CGI dir. It sounds like you must be OK on this one if other programs are
sitting in the dir you are using.
RESOLUTION:
None needed, in your case.


So,
You should be able to:
+ copy the chunk below into a text file,
+ name it 'simple.cgi'.
+ Change the first line to point at the Perl on the unix box.
+ FTP that file into a CGI dir on the unix box.
+ telnet to the unix box and
+ dos2unix simple.cgi temp.cgi <return>
+ mv temp.cgi simple.cgi <return>
+ chmod +x simple.cgi <return>
+ via a browser, enter the URL to your new simple.cgi code. Something like,


You should see 'A very simple CGI' in the browser.

--- CODE CHUNK ---
Code:
#!/usr/bin/perl
print &quot;Content-type: text/html\n\n&quot;;
print &quot;<HTML><HEAD><TITLE>Simple CGI</TITLE></HEAD>\n&quot;;
print &quot;<BODY>A very simple CGI</BODY></HTML>\n&quot;;
--- END CODE CHUNK ---

HTH Please use descriptive titles and check the FAQs.
And, beware the evil typo.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top