FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


CGI FormMail Script Part II





eday2010
OK, I found a perl script, which was kind of simple to edit. I changed the extension from .pl to .cgi at the suggestion of the writer. Now, when I tried to use it, I got server errors. When it's in my cgi-bin folder, with permission set to 775, I get the following:

Quote:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, webmaster@wnstudios.ca 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.


Reading other posts, I uploaded the script in binary ASCII mode to the cgi-bin folder. When that didn't work, I read more posts and follwed the suggestion to move it to the public_html root folder and set permission for that folder to 775 also. And yes, I changed the path for the script in my html file. When I did that, I got the following:

Quote:
Forbidden
You don't have permission to access /formmail.cgi on this server.

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


--------------------------------------------------------------------------------

Apache/1.3.34 Server at www.wnstudios.ca Port 80




So what the heck? No one has been able to solve this problem yet. Here is the top part of my form:

Code:
<form action="formmail.cgi" method="post" name="Estimate" id="Estimate">


Hopefully someone can tell me how to get it working on Frihost.
wumingsden
I don't know what is wrong with the script but i suggest reading the "Error Log" whihc should be under Stats
eday2010
The error log shows this:

Code:
[Wed Dec 14 11:23:36 2005] [error] [client 72.138.179.46] File does not exist: /home/eday2010/domains/wnstudios.ca/public_html/fade.gif
[Wed Dec 14 11:23:36 2005] [error] [client 72.138.179.46] File does not exist: /home/eday2010/domains/wnstudios.ca/public_html/404.shtml


I don't know why it's asking for those files. Anyway, I went back to try and get Bondings php code to work...

Code:
<?
$email = "your-email@something.com";
$subject = $HTTP_POST_VARS['subject'];
$message = $HTTP_POST_VARS['message'];
mail($email,$subject,$message);
?>


The above code sends just a blank email. When I add the following...

Code:
$message='Name: ';
$message.=$HTTP_POST_VARS['Name'];
$message.='\n\n';


it still sends a blank email. I have about 15 fields in my form. When I put the
Code:
mail($email,$subject,$message);
at then end of all the $message things, it only sends the last one. And if I put after each $message thing, I get an email for each set of $message thingies. How do I get it to send just one email for all of them?
Bondings
For the cgi, try to make it 755 instead of 775.

For the php, the code I gave you just adds something to the variable $message every time you use it. You should put it before the mail function.

Did you use something like this?
Code:

<?
$email = "your-email@something.com";
$subject = $HTTP_POST_VARS['subject'];

$message='Name: ';
$message.=$HTTP_POST_VARS['Name'];
$message.='\n\n';

$message.='Other field: ';
$message.=$HTTP_POST_VARS['Other_field_name'];
$message.='\n\n';

mail($email,$subject,$message);
?>
eday2010
Yes I did, but I took out the $message.='\n\n'; lines since that is what it would put in the email instead of the info I want. With the set up you asked about, it only puts the information from the last $message. into the email. So for your example, it would only write the stuff from Other_field_name. All the ones above it are ignored or missed.
Bondings
And you did use the "$message.='Other field: '; " for the second field? Weird.

I'll try to take a look at the script tomorrow if I find some time for it.
eday2010
I realized what the problem is. For each field, the $message needs to have another name, otherwise the previous one just gets written over. so if I have 2 fields in my form, the php has to me $message for the first one and $message2 for the second one, and so on (or use whatever words you want.). Now, the problem is that I have 14 fields in my form, and the mail command in php can only send 5 variables. So unless there is a way to group 5 of the fields in my form into one php variable, I won't be able to use php. Shawg...
eday2010
Shawg. Does no one have a solution? Or a mail script that works that I can use?
Bondings
eday2010 wrote:
Shawg. Does no one have a solution? Or a mail script that works that I can use?

The solution is that you just use the $message.='Other field: '; for the other fields. Please note the point between "$message" and "m". It means that you add the text after the other fields. The $message.='\r\r"; or $message.='\n\n'; just put it on a different line.
eday2010
The php "mail" command can't handle more than 5 $thingies, so I can't use it since I have 14 fields.

I'll figure it out one day Smile
Daniel15
Here you go, a simple email script. This will send you all the POST variables that are sent to the script. A similar form is used for a feedback form at my sister's website, but you can edit it to fit into your site. It sets the 'From' header to the person that sent the feedback. This form is not tested by me (I just wrote sections of it now) but it should work fine.

NOTE to Bondings: Don't use $HTTP_POST_VARS as it was used in PHP3 and is now depricated. It is no longer available in PHP5, so writing scripts that use $HTTP_POST_VARS as opposed to $_POST will not be 'future-proof'

Code:

<?php
$sendto = "youremail@example.com"; //Your email address
$submit_caption = "Send Feedback"; //The caption on the submit button

if (isset($_POST['submit']) && $_POST['submit'] == $submit_caption) {
 
    $headers = "From: {$_POST['name']} <{$_POST['email']}>";
    $subject = "Feedback - {$_POST['subject']}";

    $message = "Post from the feedback form:\r\n\r\n";

    foreach($_POST as $key => $value) {
        $message .= "{$key} = {$value}\r\n";
    }

    if(mail($sendto, $subject, $message, $headers)) {
        echo "Feedback sent!";
    } else {
        die("Feedback sending failed!<br><br>$headers<br><br>$subject<br><br>$message");
    }
} else {
    echo <<EOT
<form action="feedback.php" method="POST">
 Bla: <input type="text" name="bla"><br />
 ...etc, etc, etc... put all your fields here...
 <input type="submit" name="submit" value="{$submit_caption}">
</form>

EOT;
}
?>
Bondings
daniel15 wrote:
NOTE to Bondings: Don't use $HTTP_POST_VARS as it was used in PHP3 and is now depricated. It is no longer available in PHP5, so writing scripts that use $HTTP_POST_VARS as opposed to $_POST will not be 'future-proof'

Thanks for the tip. And yes, I normally use $_POST and $_GET most of the time.

I was searching for a script taking all possible inputs, but couldn't find it. Wink
Daniel15
Bondings wrote:
daniel15 wrote:
NOTE to Bondings: Don't use $HTTP_POST_VARS as it was used in PHP3 and is now depricated. It is no longer available in PHP5, so writing scripts that use $HTTP_POST_VARS as opposed to $_POST will not be 'future-proof'

Thanks for the tip. And yes, I normally use $_POST and $_GET most of the time.

I was searching for a script taking all possible inputs, but couldn't find it. Wink


Yeah, they're hard to find, but easy to write Very Happy. My sister needed one like that because I didn't want her bothering me every time she changes the feedback form Very HappyVery Happy... On her one, I made the form and the script seperate so she wouldn't mess up the script.
niranvv
hai,
please have a look at:

http://frihost.com/forums/vt-21009.html

here u can easily setup the files to send online datas to our email address!

Love,
Niran
www.niran.frih.net


Laughing
Related topics
Submission Forms
CGI-bin script help
Looking for easy FormMail Script
what to use
[AYS] formulario con FormMail-clone.cgi
problem with cgi perl script
CGI/Perl Script to backup a website.
CGI path in Server 2
anyone know of a good php form processer script
executing a perl script from within a script
please please beta test it (PHP coders)
RPG Rules, Settings and Enjoyment - Part I
RPG Rules, Settings and Enjoyment - Part II
Why i was inactive part III
Reply to topic    Frihost Forum Index -> Support and Web Hosting -> Web Hosting Support

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.