Forum Moderators: travelin cat

Message Too Old, No Replies

How do I get a form to work?

formmail script with apache webserver

         

cyclist

2:42 pm on May 21, 2004 (gmt 0)

10+ Year Member



Hi!
I run OS 10.3.3 on my 12" Powerbook. I connect with Airport Extreme to internet. I run Apache webserver.

I would like to get a form to work on my homepage. It seems when action is set to "mailto:****@****.com" the webbrowsers open the mailclient with a blank email. I would like the form to directly email my email adress.

I have tried to use a solution with a Perl script called "FormMail.pl" which should connect to "PostFix Enabler" which I'm about to install. But where should I locate the script "FormMail.pl"? I have administrator access to my computer, so my webpage is located at Library/WebServer/Documents.
At "WebServer" there are two folders, "Documents" and "CGI-Executables".

The script can't be found by the webbrowser. I have tried locating the script in folder "CGI-Executables" or in an folder named "cgi-bin" at same folder level. Neither works.

What do I do wrong and how do I get the form to work?

My webpage can be found at <snip> and the form is located under menu "Contact".

All suggestions will be welcome.

Thanks!

Anders
SWEDEN

[edited by: Macguru at 3:06 pm (utc) on May 21, 2004]
[edit reason] TOS [webmasterworld.com] # 13 [/edit]

cyclist

3:34 pm on May 21, 2004 (gmt 0)

10+ Year Member



OOOPS! Sorry for posting my IP-adress. I thought it would be esier to help me if the code was available.

Here goes the code from my Form.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>
<meta http-equiv="content-type" content="text/html;charset=ISO-8859-1">
<meta name="generator" content="Adobe GoLive 6">
<title>Welcome to Adobe GoLive 6</title>
</head>

<body bgcolor="black">
<div align="left">
<table width="64" border="0" cellspacing="0" cellpadding="0" height="25">
<tr>
<td></td>
</tr>
</table>
<table width="570" border="0" cellspacing="0" cellpadding="0" height="100">
<tr>
<td>
<div align="center">
<a href="http://YYY.215.40.XX" target="_top"><img src="../Home/Anders_Karlstam_PHOTOGRAPHY.gif" alt="" height="95" width="295" border="0"></a></div>
</td>
</tr>
</table>
<table width="64" border="0" cellspacing="0" cellpadding="0" height="48">
<tr>
<td></td>
</tr>
</table>
<table width="578" border="0" cellspacing="0" cellpadding="0" bgcolor="black" height="550">
<tr>
<td align="right" valign="top" width="130">
<div align="right">
</div>
</td>
<td align="left" valign="top">
<div align="left">
<form method="post" action="../../cgi-bin/FormMail.pl">
<input type="hidden" name="recipient" value="me@example.com" />
<font color="white" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">Name:</font><br>
<input type="text" name="realname" size="30"><br>
<br>
<font color="white" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"> e-mail adress (optional):</font><br>
<input type="text" name="email" size="30"><br>
<br>
<font color="white" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">
Message:</font><br>
<textarea name="comment" rows=6 cols=40></textarea><br>
<br>
<input type="submit"><input type="reset">
</form>
<p><font color="#f5f5f5" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular">UNDER CONSTRUCTION, DOES NOT WORK PROPERLY AT THIS TIME.</font></p>
</div>
</td>
<td align="left" valign="top" width="130"></td>
</tr>
</table>
<p></p>
</div>
</body>

</html>

[edited by: Macguru at 3:50 pm (utc) on May 21, 2004]
[edit reason] Specifics edited per member request [/edit]

timster

1:13 am on May 22, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The HTML looks basically fine. I would change this line:

<form method="post" action="../../cgi-bin/FormMail.pl">

to this: <form method="post" action="/cgi-bin/FormMail.pl">

The CGI-Executables folder you mention is the correct directory. Your Web server calls that directory "cgi-bin" just because they're old friends.

Depending on how Apache is set up, you may need to rename your file from FormMail.pl to FormMail.cgi. **Does anyone know if this is necessary with Apple's default Apache setup?**

After you get the form pointed as the CGI script, you'll probably need to debug it. If the CGI "just doesn't work" and you don't get an error message, add this code to the top of the FormMail script, right after the "!/usr/bin/perl -w" line:

BEGIN {
$¦=1;
print "Content-type: text/html\n\n";
use CGI::Carp qw (fatalsToBrowser warningsToBrowser);
}

(Take that out once you've got it working.)

"Congratulations. You've taken your first steps into a larger world."

cyclist

8:57 am on May 22, 2004 (gmt 0)

10+ Year Member



Thanks timster for Your reply.

I tried changing the code as you suggest, and replacing the CGI-script from an other folder to the folder "CGI-Executables".

I now get following error message:

Forbidden
You don't have permission to access /cgi-bin/FormMail.pl on this server.
Apache/1.3.29 Server at anders-karlstams-dator.local Port 80

Why do I not have access, and how do I get access?

Does this larger world ever end? :-)

A link to my webpage can be found in my profile and the form is located under menu "Contact".

Thanks
Anders

cyclist

10:14 am on May 22, 2004 (gmt 0)

10+ Year Member



The readme file that came with the script says:

The script, FormMail.pl, needs to be placed in your server's cgi-bin and the anonymous WWW user must have the ability to read/execute the script. If you do not have access to your server's cgi-bin, yet you can execute cgi scripts, you may want to try adding a .cgi extension to the FormMail.pl, renaming it to FormMail.cgi. This is probably the more common option.

This might be a solution, but I still would like to know why I do not have the ability to read/execute the script. I should have access to my server's cgi-bin.

Any suggestions on how I set access to cgi-bin (CGI-Executables)?

Thanks
Anders

cyclist

11:14 am on May 23, 2004 (gmt 0)

10+ Year Member



The problem is solved. Now I have to configure the script and link it to Postfix Enabler.

Thanks Macguru and timster for all help!

/Anders

timster

1:17 pm on May 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I still would like to know why I do not have the ability to read/execute the script.

cyclist mentioned he got this working, but for the benefit of the thread, here's a quick intro to file permissions and Web serving:

<background_info>
This has to do about every Mac user's favorite subject: Unix file permissions. Most OS X users are aware that different people can log into their Macs with different levels of access, which is great for keeping your kids from deleting your important files.

The Apache Web server on your Mac has limited privileges, to help ensure hackers visiting your Web site can't snoop aroud, damage, or even take control of your computer.

Read more about permissions here:
[osxfaq.com...]
</background_info >

So, to make a cgi work, you need to make sure "Everyone" can read and execute it. Here's a good tutorial on how to do that using the Terminal:

[macdevcenter.com...]

For those Mac users who avoid command prompts, there's another way. Download the (free) app BatChmod. Select the CGI and make sure the following boxes are checked:

Owner: R W X
Group: R X
Everyone: R X

cyclist

8:25 pm on May 24, 2004 (gmt 0)

10+ Year Member



Thanks timster for the links. I think I got the script working now. Only thing I can't figure out is the path from the script to Postfix Enabler. I have to define the path in the script so the script can forward the message to the mailserverprogram (Postfix Enabler) which sends the message as a email to me.

When filling in the form everything looks like it's working. But I do not recieve any mail. I think the path I made is incorrect. It could be some other detail I have overlooked but I would like to rule out the path.

If anyone could figure out the correct path I woud be greatful.

The script is located in /Library/WebServer/cgi-bin (CGI-Executables)
I have translated from Swedish OS X into English. I hope it is correct.

The Postfix Enabler is located in Applications and the path should look like:
/Applications/PostfixEnabler1.0 Folder/Postfix Enabler 1.0.9

Should the path from the script to the application look something like the path above?

In the folder "PostfixEnabler1.0 Folder" is also along with the application "Postfix Enabler 1.0.9" a folder named "__MACOSX" and inside this folder is a small application (16 K) called "Postfix Enabler 1.0.9". What is this small application for?

I'm thankful for all help.

/Anders

cyclist

8:58 pm on May 24, 2004 (gmt 0)

10+ Year Member



I might add that the default path is defined like this:
/usr/lib/sendmail

The whole line in the script looks like:
$mailprog = '/usr/lib/sendmail -i -t';

This is the explanation in the readme-file:
This variable must define the location to your server's sendmail program. If this is incorrect, form results will not be mailed to you. Specifying the parameters in this variable is new in v1.91, and we have included the -i parameter so that a single period on a line by itself will not end the message. -t instructs sendmail to read the recipient list from the message text.

This is what I use now (probably does not work):
$mailprog = '/Applications/PostfixEnabler1.0 Folder/Postfix Enabler 1.0.9 -i -t';

I'm lost in all possible variations of the path. I have tried several. I must be missing something.

All help and suggestions are welcome.

/Anders

cyclist

9:07 pm on May 25, 2004 (gmt 0)

10+ Year Member



I sent a private message to timster who kindly replied:

If you click on a file, e.g., your Postfix Enabler, and select "Get Info" (Apple-i) the third item under the "General" area is "Where." This gives you the path to the file, but unfortunately, Apple hasn't made this display a "real" Unix path, so you have to convert it. To do this, remove the name of the root (leftmost) directory, change colons to slashes, and add backslashes before spaces.

For instance:
Macintosh HD:Users:smith:A program.pl
changes to:
/Users/smith/A\ program.pl

Case is important here.

-timster

cyclist

9:25 pm on May 25, 2004 (gmt 0)

10+ Year Member



I have now tried so many different possible paths so I'm leaning at there is some other problem in the configuring of the script or the preferences of Postfix Enabler. One of all the combinations I have tried ought to be OK.

This path is what I believe to be correct:
/Applications/PostfixEnabler1.0\ Folder/Postfix\ Enabler\ 1.0.9.app

The whole line of code in the script looks like:
$mailprog = '/Applications/PostfixEnabler1.0\ Folder/Postfix\ Enabler\ 1.0.9.app -i -t';

I have tried:
/OS\ X/Applications/PostfixEnabler1.0\ Folder/Postfix\ Enabler\ 1.0.9.app

I have tried:
OS\ X/Applications/PostfixEnabler1.0\ Folder/Postfix\ Enabler\ 1.0.9.app

I have tried:
Applications/PostfixEnabler1.0\ Folder/Postfix\ Enabler\ 1.0.9.app

I have tried with the Swedish "/Program/" instead of the English "/Applications/".
I have tried several different combinations with or without ".app" at the end.

I feel lost in the jungle!

What should I do next? Look for other errors in the path or does it look fine?

Thanks
/Anders

cyclist

4:30 pm on May 26, 2004 (gmt 0)

10+ Year Member



YES! At last!
I found the right path:
/usr/sbin/sendmail

This is what the correct line of code looks like:
$mailprog = '/usr/sbin/sendmail -i -t';

/Anders