Forum Moderators: coopster
Hope your all well.
Hoping for some help. I have recently created a PHP contact form to be used on my website. Everything works fine with the email being sent correctly and a nice thank you message notifiying the user the message has been sent.
However, I have come to use the same contact form on a different project and low and behold it doesn’t work.
I'm not a php bod but I thought it would be straight forward as everything is the same on the servers I’m using (hosts etc) so why it doesn’t work I don’t know.
The problem lies at when the user adds contact info (name, email, message) and presses send. Rather than displaying the thank you message, a fields are missing message is displayed instead (which should only happen if one of the said fields have not been completed).
I would be very grateful if someone could help me or point me in the correct direction. I’m confused and frustrated!
Kind regards,
Lee
[edited by: LeeAllen at 3:03 pm (utc) on Feb. 16, 2004]
With out looking to deep into what you are doing and with out seening any of the code I would guess that your globals are turned off on the server which its not working on. Do you ever use $_GET or $_POST on the script? Even though this is the same host, doesnt mean its the same server or that they are configed the same. The first server may be an old server they "forgot" about.
PS. you may want remove the links as they are not allowed here.
method=post:
$name = $_POST['name'];
method=get:
$name = $_POST['name'];
This will then give your $name the value you are looking for. If I remember correctly they will work even if globals are turned on, but dont hold me to that its been awhile since they where turned on for me.
Another approach might be to use extract($_POST) at the top of the script. Depends on how the script is set up. If it is using a lot of functions that reference the $_POST variables it might be problematic, but if it is simple script that only uses native PHP functions it will probably work.
WBF
mainly try to stick to the relevant code and don't just paste the whole script.
PHP Code
<?php
if (($Name == "") ¦¦ ($Email == "") ¦¦ ($Comments == ""))
{
echo "<form name=form method=post action=contact_thanks.php>";
echo "<h1>Field Missing</h1>";
echo "<p class=bodymd>All three fields of this form are required,</p>";
echo "<p class=bodymd>Fill in the ones you missed, they are listed below.</p>";
}
if ($Name == "")
{
echo "<p class=bodymd>Your Name<br><input type=text name=Name></p>";
}
else
{
echo "<input type=hidden name=Name value=$Name>";
}
if ($Email == "")
{
echo "<p class=bodymd>Your Email<br><input type=text name=Email></p>";
}
else
{
echo "<input type=hidden name=Email value=$Email>";
}
if ($Comments == "")
{
echo "<p class=bodymd>Comments or Questions<br><textarea name=Comments rows=5 cols=40></textarea></p>";
}
else
{
echo "<input type=hidden name=Comments value=$Comments>";
}
if (($Name == "") ¦¦ ($Email == "") ¦¦ ($Comments == ""))
{
echo "<input type=submit name=Submit value=Send>";
echo "<input type=reset name=Reset value=Clear Form>";
echo "</form>";
}
else
{
$message = "Name: $Name\nEmail: $Email\nComments: $Comments\n";
$extra = "From: $Name\r\nReply-To: $Email\r\n";
mail ("me@example.com", "Website Email", $message, $extra);
echo "<h1>Thanks for your enquiry, $Name.</h1>";
echo "<p>A response will be sent to $Email as soon as possible.</p>";
}
?>
and the corresponding html
<form name="form" method="post" action="contact_thanks.php">
<p class="bodymd">Your Name<br>
<input type="text" name="Name">
</p>
<p class="bodymd">Your Email<br>
<input type="text" name="Email">
</p>
<p class="bodymd">Comments or Questions<br>
<textarea name="Comments" rows="5" cols="40"></textarea>
</p>
<p class="bodymd">
<input type="submit" name="Submit" value="Send">
<input type="reset" name="Reset" value="Clear Form">
</p>
</form>
[edited by: jatar_k at 8:19 pm (utc) on Feb. 16, 2004]
[edit reason] generalized email [/edit]
<?phpif (($Name == "") ¦¦ ($Email == "") ¦¦ ($Comments == ""))