Contact action php behaving wrong...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
truepal20032001
Forum Commoner
Posts: 27
Joined: Mon Jun 25, 2007 8:28 pm

Contact action php behaving wrong...

Post by truepal20032001 »

my code is misbehaving, whats wrong.

i want it to send my contact information, but it will always give me the wrong report even if i inserted the data correctly.

OUTPUT ALWAYS
===============================================
ERROR!
===============================================

php code:
===========================

Code: Select all

<div align="center">
<h1><strong></p>
</div>
<div align="center">
<div align="center">
<div align="center">
<meta http-equiv="refresh" content="2;url=/home.html">


<?php
$name = $_POST[name];
$email = $_POST[email];
$comment = $_POST[comment];
$msg = "Name: $_POST[name]\n";
$msg.= "Email: $_POST[email]\n";
$msg.= "Phone: $_POST[phone]\n";
$msg.= "Comment/Message:\n";
$msg.= "$_POST[comment]\n<br><br>";
$msg.= "Message recieved: ".date('H:i, jS F');
If($name && $comment && $email){
@mail('truepal20032001@yahoo.c...
echo "Thankyou! You'll be replied soon.</strong></h1>
<p><strong><br />
</strong><br />
<strong></strong></p>
<p>";
echo '<html><h1 align="center"><img src="info/check.jpg"</html>';
}
else{
echo "ERROR!!</strong>"}

?>
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

What does the form look like? Is it being set via POST or GET? Are you filling out all fields?
(#10850)
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Re: Contact action php behaving wrong...

Post by patrikG »

Try using quotation marks when using associative arrays

Code: Select all

$name = $_POST["name"];

etc.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

Are the name attributes in your form's input fields spelled correctly? A var_dump($_POST) might reveal what the problem is.

Also, it's rarely ever a good idea to use the shut-up operator (@) as you have on mail() -- if you're worried about users seeing errors in production, use error_reporting() to hide them, but in development, you'll spend a lot more time debugging when relevant information is being muted.
truepal20032001
Forum Commoner
Posts: 27
Joined: Mon Jun 25, 2007 8:28 pm

Re: Contact action php behaving wrong...

Post by truepal20032001 »

patrikG wrote:Try using quotation marks when using associative arrays

Code: Select all

$name = $_POST["name"];

etc.
oh i see what you are saying:
when php looks at
"$_POST[email];" It looks at them as values, but when they are
"$_POST["email"];" It looks at them as strings right, that would make more sense thanks
User avatar
Ambush Commander
DevNet Master
Posts: 3698
Joined: Mon Oct 25, 2004 9:29 pm
Location: New Jersey, US

Post by Ambush Commander »

Not so much values, but constants; the general jist is correct though.
Post Reply