0

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>&nbsp;</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.

Edited by JerieLsky: n/a

4
Contributors
21
Replies
22
Views
7 Years
Discussion Span
Last Post by ivatanako
Featured Replies
  • [QUOTE=JerieLsky;986300]Here is a link to download the .html and .php file that i'm working with. [url]http://www.adrive.com/public/c5104686df888c76ed104887a1e7be92c68f7c538fba57f8f36addd5e82f624c.html[/url] Ahm, i'm actuallly using wamp server, I've set them ONLINE and started all services too.. so I think I don't have a problem with it though.[/QUOTE] I can assure that the code that this … Read More

  • you are trying to run php from the local file system [noparse]/C:/Documents and Settings/rEd_xiii21/Desktop/programming/ERDI Website Final/Duplicate of Edited Site/[/noparse] that wont work, even if it is the same folder php has to run as [noparse]http://127.0.0.1/filepath/filename.php[/noparse] (or localhost/) move all the files you wish to work on, below the folder assigned … Read More

0

you should have check first if the fields are not empty?

<?php
// you should check if this fields are empty
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";
}

For now, you might already get the idea. Hope it helps

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?

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?

you are checking if the post method has been set or is the submit button been submitted.

0

Ahm, what is then the problem on the code why does it not display anything?

0

the problem is, this part

<td width="350" colspan="2"><textarea cols="59" rows="5"></textarea name="question"></td>

try changing it to this

<td width="350" colspan="2"><textarea cols="59" rows="5" name="question"></textarea></td>

and use the code that i've given earlier

Edited by ivatanako: n/a

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..

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..

do you have a mailserver? i tested your code on my machine.. and im sure that it is working.

try removing the mail function then try outputting just plain text

0
if(mail($email,Inquiry,$message))

try changing the 'inquiry'

Edited by ivatanako: n/a

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?

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,

Edited by almostbob: n/a

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?

can you post the whole code?

0

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."; }

Edited by almostbob: n/a

0

try this:

<?php
//The button is presed
	if (isset($_POST["submit"]))
	{
		$name = $_POST['name'];
		$email = $_POST['email'];
		$question = $_POST['question'];
		$message = "Message from $name \n Message: $question";
		
		$sent_mail = mail($email,$message,$message);
		if($sent_mail) {
		echo "Message sent.";
		die();//Stop here
		} else {
		"Message was NOT Sent.";
		die();
		}
	}
	else {	
	?>
		<table cellpadding="0" cellspacing="5" border="0" width="500" align="center">
	    <form name="FAQ" method="post" action="mail.php">
	    
	    <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 name="question" cols="59" rows="5"></textarea></td>
	    </tr>
	    <tr>
			<td colspan="2" align="right"><input type="submit" value="Submit" name="submit"></td>
	    </tr>
	    <tr>
			<td>&nbsp;</td>
	    </tr>
	    </form>
	    </table>
		
		<?php
		}
		?>

This worked on my server. Tested!

0

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.

1

Here is a link to download the .html and .php file that i'm working with.

http://www.adrive.com/public/c5104686df888c76ed104887a1e7be92c68f7c538fba57f8f36addd5e82f624c.html

Ahm, i'm actuallly using wamp server, I've set them ONLINE and started all services too.. so I think I don't have a problem with it though.

I can assure that the code that this guys have given are all working. Your code even works, it prints "ME" after i click the submit button.

Have you put your files in the WWW directory?? in wamp by default, it is located here C:\wamp\www\

then try accessing it like this

http://localhost/E-FAQ.html

1

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)

Edited by almostbob: n/a

0

Whew!! I guess that solves the problem. Well thanks guys, you we're of great help add up more reputations to you guys.. :D

0

Hi, another question.. What if i receive this kind of error:

403 Forbidden. You don't have permission to access /Duplicate of Edited Site/< on this server.

0

Hi, another question.. What if i receive this kind of error:

i suggest you create a new topic for this one. And mark this one as solved. There more people could help you with your problem :)

Edited by ivatanako: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.