Forum Moderators: coopster

Message Too Old, No Replies

php formmail script

jack's formail

         

ControlZ

6:22 pm on Sep 8, 2005 (gmt 0)

10+ Year Member



Need help with a small problem. Configured Jack's formail script without a problem. Inserted a checkForm JavaScript to check for required fields. Fields not completed receive a pop-up warning.

Noticed if someone does not enter a properly formatted email address, they are redirected to a page with a php error.

Warning: Cannot modify header information - headers already sent by (output started at /home/imlendin/public_html/an/phpmail/formmail.php:259) in /home/imlendin/public_html/an/phpmail/formmail.php on line 63

Line 63 refers to a line with Jack's formail which is called the "mighty error function." Evidently, because of the improperly formatted email address the script is generating an error page.

Can anyone tell me how I can change the formail script to redirect a user to an error page I create rather then sending them to a php error page or the standard Jack's error page? I believer looking at the code below, I have the error page value set to 0.

Here's the snippet of script which contains the error function:

// our mighty error function..
function print_error($reason,$type = 0) {
build_body($title, $bgcolor, $text_color, $link_color, $vlink_color, $alink_color, $style_sheet);
// for missing required data
if ($type == "missing") {
if (missing_field_redirect) {
header("Location: $missing_field_redirect?error=$reason"); Line 63
exit;
} else {
?>
The form was not submitted for the following reasons:<p>
<ul><?
echo $reason."\n";
?></ul>
Please use your browser's back button to return to the form and try again.<?
}
} else { // every other error
?>
The form was not submitted because of the following reasons:<p>
<?
}
echo "<br><br>\n";
echo "<small>This form is powered by <a href=\"http://www.somedomain.com/scripts/\">Jack's Formmail.php ".VERSION."</a></small>\n\n";
exit;
}

StupidScript

3:05 am on Sep 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



 if (missing_field_redirect) {

should be

 if ([b]$[/b]missing_field_redirect) {

By using

missing_field_redirect
instead of
$missing_field_redirect
you are sending output to STDIN, which is messing with your
header
function.

ControlZ

3:46 am on Sep 9, 2005 (gmt 0)

10+ Year Member



Cool - I'll try that. What is STDIN?

StupidScript

4:31 am on Sep 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



STandarD INput ... the buffered cache that the operating system uses for floating data ... in particular, the most-recent output generated by something ... keystrokes ... script output ... etc.

In your code, the error generated by the missing variable ("missing_feld_redirect" without the quotes is neither a string nor a variable ... it's just undefined gobbledygook to the script) or improperly-formatted string (where a properly-formatted string would be like "missing_field_redirect", with the quotes to define the string) was/is the thing that was sent to STDIN, which violated the rules for proper execution of the

header()
function. No output to STDIN allowed before you invoke a
header()
-family function.

BTW, I checked your code against the current code to find the content of my last post.

[edited by: coopster at 2:34 pm (utc) on Sep. 9, 2005]
[edit reason] unlinked url [/edit]

ControlZ

4:06 pm on Sep 9, 2005 (gmt 0)

10+ Year Member



Thanks so much. Excellent explanation! I did catch the URL before it was removed. :)

Is it possible to turn off the error function? I edited the script as you suggested, but I just got an email from client who says they received the error about an unauthorized domain. Not possible from what I know, because I included all domain names they own as well as their IP address. My only guess is that this may be happening since they are using a shared IP.

I have used this script many times, and never seen the unathorized domain error, but all the other sites I have installed the script on used dedicated IP addresses.

I would really like to disable the security and error messages. Is that possible?

StupidScript

4:42 pm on Sep 9, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Inserting

error_reporting(0);

near the top of your code will do it. PHP Manual [us2.php.net]