Please Read! php problem.
I'm just new in php actually and this is the problem that i have been encountering lately. I actually have one .html file and .php file, on the .html file I created a form which looks like this:
<table cellpadding="0" cellspacing="5" border="0" width="500" align="center">
<form name="FAQ" method="post" action="question.php">
<span style="font-family: Arial, Helvetica, sans-serif;font-size: 12px;font-style: normal;line-height: normal;font-weight: normal;font-variant: normal;text-transform: none;color: #000000;">
<tr>
<td width="150"><p class="content">Name: * </td>
<td width="350"><input type="text" size="55" name="name"></td>
</tr>
<tr>
<td width="150"><p class="content">Email Address: * </td>
<td width="350"><input type="text" size="55" name="email"></td>
</tr>
<tr>
<td width="150"><p class="content">Question: * </td>
</tr>
<tr>
<td width="350" colspan="2"><textarea cols="59" rows="5"></textarea name="question"></td>
</tr>
<tr>
<td colspan="2" align="right"><input type="submit" value="Submit" name="submit"></td>
</tr>
<tr>
<td> </td>
</tr>
</form>
</table>
And here is the .php file:
<?php
if (isset($_POST["submit"]))
{
$name = $_POST['name'];
$email = $_POST['email'];
$question = $_POST['question'];
$message = "Message from $name \n Message: $question";
mail($email,Inquiry,$message);
echo "Message sent.";
}
else
{
echo "Sending failed, please input the required fields.";
}
?>
The problem that i'm encountering here is, in each textbox in the.html file i just live it blank, once that i click on the "Submit" button, the output that would be displayed is "Message sent.", instead of "Sending failed, please input the required fields."
Please help me here.. Thanks, been trying to solve it for almost 6hours already, and still i get the same output.
thanks in advance.
JerieLsky
Junior Poster in Training
63 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
I used the code that you suggested but nothing has been displayed or no output at all. What is the use of the isset() function in the if-else statement then?
JerieLsky
Junior Poster in Training
63 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
Ahm, what is then the problem on the code why does it not display anything?
JerieLsky
Junior Poster in Training
63 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
Seriously, still no output. I even tried adding this statement in the .php file
echo "Me";
it actually showed nothing. I added that statement after the <?php tag and before the if-else statement, here:
<?php
echo "Me";
if($_POST['name']=="" || $_POST['email']=="" || $_POST['question']=="")
{
echo "Sending failed, please input the required fields.";
}
else
{
$name = $_POST['name'];
$email = $_POST['email'];
$question = $_POST['question'];
$message = "Message from $name \n Message: $question";
if(mail($email,Inquiry,$message))
echo "Message sent.";
else
echo "Message sending failed";
}
?>
so confusing..
JerieLsky
Junior Poster in Training
63 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
this is what i did in the .php file, i omitted the contents and i just replaced it with this statement but still no output:
<?php
echo "Me.";
?>
what do u think is causing the problem?
JerieLsky
Junior Poster in Training
63 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
php forms can be self processing, its easy to debug one script, try
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- @(#) $Id$ -->
<head>
<title>HTML Template</title>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
</head>
<body>
<?php if (isset($_POST["submit"])) {
if(!$_POST['name'] || !$_POST['email'] || !$_POST['question'] )
{ echo "Required fields not completed, please input the required fields."; }
else { $name = $_POST['name'];
$email = $_POST['email'];
$question = $_POST['question'];
$message = wordwrap("Message from $name \n Message: $question", 70);
if(!mail($email,"Inquiry",$message)) {echo "Sending failed, please input the required fields."; } else echo "Message sent.";
} } ?>
<form name='FAQ' method='post' action='<?php echo $_SERVER["PHP_SELF"]; ?>'>
<table cellpadding='0' cellspacing='5' border='0' width='500' align='center'>
<tr>
<td width='150'><p class='content'>Name: * </td>
<td width='350'><input type='text' size='55' name='name'></td>
</tr>
<tr>
<td width='150'><p class='content'>Email Address: * </td>
<td width='350'><input type='text' size='55' name='email'></td>
</tr>
<tr>
<td width='150'><p class='content'>Question: * </td>
</tr>
<tr>
<td width='350' colspan='2'><textarea cols='59' rows='5' name='question'></textarea></td>
</tr>
<tr>
<td colspan='2' align='right'><input type='submit' value='Submit' name='submit'></td>
</tr>
</table>
</form>
</body>
</html>
but the message is only being sent to the sender, no address is specified for you
Try replacing line 16
if(!mail('myaddress@mysite.com',"Inquiry",$message,"Cc:$email\r\n")) {echo "Sending failed, please input the required fields."; } else echo "Message sent.";
message to "customer service", copy to sender
all necessary html headers are sent before any script output, in case malformed pages are being thrown out by the server,
almostbob
Posting Sensei
3,147 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
this is a better line16
if(!mail('me@mysite.com',"Inquiry","$message","From: $email " . "\r\n" . "Cc: $email"."\r\n")) {echo "Sending failed,"; } else { echo "Message sent."; }
almostbob
Posting Sensei
3,147 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
Hi there almostbob, thanks for the quick response.. well actually i'm still having a problem with one line that you've give which is in line 18 stating:
<form name='FAQ' method='post' action='<?php echo $_SERVER["PHP_SELF"]; ?>'>
The problem is in the action='<?php echo $_SERVER["PHP_SELF"]; ?>'
Once that i click the Submit button a "Page Load Error" occurs saying
"Firefox can't find the file at /C:/Documents and Settings/rEd_xiii21/Desktop/programming/ERDI Website Final/Duplicate of Edited Site/<?php echo $_SERVER["PHP_SELF"]; ?>."
What does the code - action='<?php echo $_SERVER["PHP_SELF"]; ?>' - actually do?
Thanks for your time.
JerieLsky
Junior Poster in Training
63 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
JerieLsky
Junior Poster in Training
63 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0
you are trying to run php from the local file system /C:/Documents and Settings/rEd_xiii21/Desktop/programming/ERDI Website Final/Duplicate of Edited Site/
that wont work, even if it is the same folder
php has to run as http://127.0.0.1/filepath/filename.php (or localhost/)
move all the files you wish to work on, below the folder assigned as localhost in your php/wamp/IDE settings and access them though the localhost url
I do not know what php system version/wamp/ide you have installed but the errors now seem to be simply method problems, but a solution is getting closer (nervous fingers crossed)
almostbob
Posting Sensei
3,147 posts since Jan 2009
Reputation Points: 571
Solved Threads: 376
Whew!! I guess that solves the problem. Well thanks guys, you we're of great help add up more reputations to you guys.. :D
JerieLsky
Junior Poster in Training
63 posts since Jul 2009
Reputation Points: 10
Solved Threads: 0