Jump to content

Recommended Posts

Greetings!

 

I've just taken over hosting a website (I moved it to a server I use) which contains formmail code. The formmail error checking process (from what I've been told) used to work OK. But, after moving the site to the new server and testing the 'contact us' page (which contains the unchanged formmail code), I've not been able to get a successful submission of the form/data. I've been trying to figure this our for several days, but must ask for outside help.

 

I fill in the input boxes with valid entries (my name & my valid email address, in both places) yet continually receive the following error message/page:

 

  the following fields must be filled in.

 

  1. You forgot to write your name

  2. Your forgot to write your email address.

 

HELP!  :-[

 

Thanks! Glen

(I hope I've put the code properly on this page. Didn't see a 'code' parameter in which I should have enclosed it!)

 

 

Here's the 'contact us' page code:

        <form action="php/forfriend.php" method="post" enctype="multipart/form-data">

<p>

<input type="hidden" name="recipient" value="me@mywebsite.com" />

<input type="hidden" name="subject" value="Friend Referral: Name + Email " />

<span class="style1">Thank for taking the time to contact us!</span>

</p>

<p>

<span class="style1">

<span class="style2">TELL A FRIEND </span>

Your Name: <input name="name" type="text" id="yourname" value="Name" size="20"  />

Your Email: <input name="email" type="text" id="youremail" value="E-Mail" size="20" />

</span>

</p>

<p>

<span class="style1">

Friends Name: <input name="friendsname" type="text" id="friendsname" value="Name" size="20" />

Friends Email: <input name="friendsemail" type="text" id="friendsemail" value="E-Mail" size="20" />

</span>

</p>

<p class="style1">Note for Friend: </p>

<p class="style1">

<textarea name="notetofriend" cols="30" rows="10" id="notetofriend"></textarea>

</p>

<p>

<input type="submit" name="submit" value="E-Mail Me!" />

<input type="hidden" name="redirect" value="www.mywebsite.com/home.html" />

</p>

<p class="style1"> </p>

</form>

 

Here's the formmail code:

<?

$mail="me@mywebsite.com";

$subject="People Interested in Knowing More";

$thank="thank.html";

 

$no_name="You forgot to write your name";

$mail_error="Your forgot to write your email address.";

 

$error_title="wrong parameters";

$back='#ffffff';

$text='#000000';

$h2='#cccccc';

$error_message="the following fields must be filled in.";

 

$result=1;

if($yourname==""){

$result=0;

$error="<li>$no_name</li>";

}

else{

$mailbody="Name : $yourname\n";

}

if ($youremail!==""){

if (!eregi("^.+@.+\\..+$", $youremail)){

$error4="<li>$mail_error</li>";

$result=0;

}

}

else{

$youremail=trim($youremail);

}

$mailbody.="name: $yourname\n";

$mailbody.="email: $youremail\n";

$mailbody.="friendsname: $friendsname\n";

$mailbody.="friendsemail: $friendsemail\n";

$mailbody.="notetofriend: $notetofriend\n";

$mailbody.="---------------\n";

$mailbody.="USER INFO\n";

$mailbody.="---------------\n";

$mailbody.="User use :$HTTP_USER_AGENT\n";

$mailbody.="Send via :$HTTP_VIA\n";

$mailbody.="ip adress is :$REMOTE_ADDR\n";

$mailbody.="Remote host is : $REMOTE_HOST\n";

$mailbody.="-------------\n";

$date=date("m/d/Y H:i:s");

$mailbody.="SERVER INFO\n";

$mailbody.="send date/time : $date\n";

$mailbody.="Came From web : $HTTP_HOST\n";

$mailbody.="Came from Ip number : $SERVER_ADDR\n";

$mailbody.="FILE name : $SCRIPT_FILENAME\n";

if ($result==1){

mail($mail,$subject,$mailbody,"From: $email\n");

Header ("Location: $thank");

}

if ($result!=="1"){

echo ("<body bgcolor=$back text=$text><title>$error_title</title>

<center><h2><font color='$h2'>$error_message</font></h2></center><ol>$error$error1$error2$error3$error4

$error5$error6</ol></center></body>");

}

?>

Link to comment
https://forums.phpfreaks.com/topic/38918-formmail-error-used-to-work-ok/
Share on other sites

It's "failing" because the code assumes register_globals is ON and your new server has register_globals set to OFF - the default value with php for quite some time.  Modify the formmail code to abstract passed values from the $_POST array, for example:

 

$yourname = $_POST['yourname'];

Thank you, AndyB, for your input.

 

I contacted the server people. They tell me the "register_globals" is ON.

Here's what I see in the link they sent me:

 

register_globals [Local Value] = On [Master Value] = Off

 

 

They tell me to try it again, the form page and formmail script. It still it comes up with the error message when submitted:

 

  the following fields must be filled in.

 

  1. You forgot to write your name

  2. Your forgot to write your email address.

 

SIGH ...  ::)

 

 

 

Maybe this will help? (a link to the actual page): http://www.youluckydawg.com/emailfriend.html

 

 

BTW, your suggestion to

Modify the formmail code to abstract passed values from the $_POST array, for example:

 

Code:

 

$yourname = $_POST['yourname'];

 

 

Uh ... I don't know/see where to put that. Can you help me understand your request/suggestion?

 

 

 

Thanks again, AndyB ... and anyone else who wants to 'have at it' here - PLEASE DO!  :)

 

 

Glen

Greetings again!  ;)

 

I've just heard from the hosting company. They've turned both "register_globals" ON (Local Value and Master Value) ...

 

And, retried the script. To no avail - same error message!

 

  the following fields must be filled in.

 

  1. You forgot to write your name

  2. Your forgot to write your email address.

 

 

What's a fellow to do now?  :(

 

I do appreciate your time (AndyB and whomever else would please feel free to comment)...

 

Cheers!

Glen

:) :) :)

 

I guess it took a few hours to get the 'change' to take place on the server this morning.

 

I tried the form on the website and suddenly it started working!!!!!!!!

 

Thanks, AndyB, for your help in this. It was the "register_globals" apparently.

 

Take care!

 

Glen

Well, I don't understand why the flipping thing is working (or how it ever worked). If you look closely at the form, you'll see that the input for the user's name is called name NOT yourname, and the input for the user's email is called email NOT youremail. The ids used have zero significance or use.

 

To get the values POSTed by your form, you need to examine the values of the variables $name and $email (or $_POST['name'] and $_POST['email'] which will work regardless of how register_globals is set).

 

Sorry I didn't spot that the first time I looked ...

AndyB ....

 

Well, I don't understand why the flipping thing is working (or how it ever worked). If you look closely at the form, you'll see that the input for the user's name is called name NOT yourname, and the input for the user's email is called email NOT youremail. The ids used have zero significance or use.

 

I changed those errors (name vs yourname & email vs youremail) and that helped the thing along. Sorry I did not mention that when I also confirmed that the form was working after the register_globals permission was set to ON.

 

Glen

Thank you for the 'pat on the brain' ... I'll redo the code to use a more secure method. I'll investigate the process, as you describe it:

To get the values POSTed by your form, you need to examine the values of the variables $name and $email (or $_POST['name'] and $_POST['email'] which will work regardless of how register_globals is set).

 

 

I really appreciate your follow-up with your astute comment/recommendation.

Grin then I guess it really is solved.

 

I'd recommend you code as if register_globals is OFF (the default value on all recent versions of php). It's more secure, better practice, and well worthwhile 'doing it right'.

 

 

Thanks, AndyB

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.