Forum Moderators: coopster
I have been using this form for over six years now, but it is now no longer working. I get the page displayed correctly with all the information, but when the button is clicked to actually send this data to me, it just displays the page with no data and nothing is sent.
It is supposed to send the information my two email address and then display the webpage that the Message was sent.
I had problem two years ago after an update and had to add "php_flag register_globals on" to my .htaccess file in direcorty of my script. That is still in place. I am guessing something has changed recently due an upgrade on the hosting site that is again restricting something.
Please look through my code and suggest or correct what you think is incorrect.
--begin---
<HTML>
<HEAD>
<TITLE>Confirmation page, click submit if correct</TITLE>
</HEAD>
<BODY BACKGROUND="image.jpg">
<?if($argv[0]=="sendit" && isset($body)):
Mail("email1@example.com,email2@example.com",
"Normal Subject - The data", $body);?>
<H3>Message sent. Thank you!</H3>
<P>
<A HREF="http://www.example.com/tryagain.htm">Return to the main webpage</A>
<?else:;
$body = "
$subject
Your Name : $name
E-Mail : $mail
$who
"
?>
The following Email will be sent:
<P>
<PRE>
<?echo $body;?>
</PRE>
<form action="<?echo $PHP_SELF;?>?sendit" method="POST">
<input type=hidden name="body" value="<?echo $body;?>">
<input type="submit" value="Click to send this information to me">
</FORM>
<?endif;?>
</BODY>
</HTML>
---end---
I have been reading about others that have had problems and they had to change POST to $_POST['email'], but that didn't help and quite likely I just implemented it incorrect.
If there is something I am leaving out, let me know.
Thank you very much for any help. I am very new PHP coding, as I am sure you can tell with the above.
-paul
[edited by: dreamcatcher at 8:46 pm (utc) on Sep. 4, 2007]
[edit reason] Use example.com, thanks. [/edit]
You're on the right track - any of the variables you have coming to you from your form need to be referred to as
$_POST['variablename']
like it looks like you need to do that with $body - it becomes $_POST['body']
You should also change your form's action attribute to $_SERVER['PHP_SELF']
I made the following changes:
<?if($argv[0]=="sendit" && isset($_POST['body'])):
Mail("email1@example.com,email2@example.com",
"Normal Subject - The data", $_POST['body']);?>
...
<form action="<?echo $_SERVER['PHP_SELF'];?>?sendit" method="_POST['body']">
<input type=hidden name="body" value="<?echo $_POST['body'];?>">
I still have the same problem. This is what I tried earlier, but figured I must have done something wrong or am just not understanding how the $_POST is supposed to be used. The variable within the body don't need to be changed, as I can see it. I tried to play with them, but that really breaks everything :)
Could this be a server side setting beyond the .htaccess file, or am I still missing something within my simple code?
Thanks again for the help.
If your script has worked for years and suddenly it doesn't work any more, then the most likely cause is that your host has turned off register_globals [php.net].
Any variables that come to you from a form using method="get" or the query string on the address (example.com/page.php?index=4) are referenced as $_GET['variablename'], in this case $_GET['index'].
Any variables that come to you from a form with method="post" are referenced by $_POST['variablename']
If body came from a posted form, then, it should be referenced as $_POST['body']. IF, however, you got it from somewhere else, then $body may still be correct.
In your form declaration, change method="_POST['body']" back to just method="post" - here you're not referring to a variable name, you're specifiying an attribute for the form, which is either post or get.
I've never used argv in a php script so I have no idea as to its correctness. Personally I would use?sendit=true in the form's action, then test:
<?if(isset($_GET['sendit'] && isset($_POST['body'])):
but again, I'm not saying what you're doing there is wrong.
After playing around with the variables throughout the code ( and fixing an induced error ), I have gotten it to work again.
Not sure what changed over the past year to break this, but I have changed the following, with your help to get it to work again.
Differences ...
< <?if($argv[0]=="sendit" && isset($body)):
< "Normal Subject - The data", $body);?>
< $body = "
< <?echo $body;?>
< <form action="<?echo $PHP_SELF;?>?sendit" method="POST">
< <input type=hidden name="body" value="<?echo $body;?>">
---
> <?if(isset($_GET['sendit']) && isset($_POST['body'])):
> "Normal Subject - The data", $_POST['body']);?>
> $_POST['body']= "
> <?echo $_POST['body'];?>
> <form action="<?echo $_SERVER['PHP_SELF'];?>?sendit" method="POST">
> <input type=hidden name="body" value="<?echo $_POST['body'];?>">
Once again, it works great. I sent an email into the hosting folks and will pass along the changes that got this to work. If they
reply with a reason why my old code broke, I will post a follow up here.
Thanks,
-paul
HiDude