Contact page php

Trying to complete contact page. Would like message to refresh. Here’s what I have thus far.

<html>

<head>

<style type="text/css">


</head>

<body>

<br>
<?php
if(isset(_POST['submit'])){
$name = htmlspecialchars($_POST['name']); 
$subject = htmlspecialchars($_POST['subject']); 
$from = htmlspecialchars($_POST['mail'];
$message = htmlspecialchars($_POST['message']; 

$to = "[email protected]"; 
$headers = "From:" . $from; mail($to,$subject,$message, $headers); 
$txt = "You have received an email from".$name.".\n\n.$message;
"<meta http-equiv='Refresh' content='0; URL=contact.php'>";

echo "<b>Message successfully sent</b>"; 
mail($to,$subject,$txt,$headers);

}
?>
<br>


<div align="center">

<form action="test.php" method="post">
<input type="text"  name="name" placeholder="name"><br /><br />
<input type="text"  name = "email" placeholder="email"><br /><br /> 
<input type="text" name="subject" placeholder="subject"><br /><br />
<textarea name="message" cols="45" rows="9" placeholder="Message..."></textarea>
<br />
<br />
<input type="image" src="sendbutton.jpg" name="submit"></div>

</td>

</tr>

</table>

</td>

</tr>

</table>

</form>

</td>

</tr>

</table>

</center>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

<br>

/p>

</div>

</body>

</html>

This isn’t going to work. See how you are assigning a variable in the first line, but just quoting text on the second? The processor doesn’t know what you want to do, so it just stops.

Thanks for the information. Appreciate it. Is it possible to have the “message sent” refresh, at all?

You can, but you need to tell the interpreter what to do with the string, you can’t just declare the string and expect it to know what you meant.

1 Like

I’m not sure how to do that.

You just need to give a command, you are doing it the very next line down.

1 Like

You lost me, Is this the next line?

"<meta http-equiv='Refresh' content='0; URL=contact.php'>";

then

to this

and in the general php forum. how can you not know what he means?
output, id est, echo or print.

<?php echo "show this message."; ?>

He just said next line. I wasn’t clear as to what he was referring to.

//Line I initially brought up
$txt = "You have received an email from".$name.".\n\n.$message; 
// The next line after that
"<meta http-equiv='Refresh' content='0; URL=contact.php'>";
1 Like

So, what changes do I need to make?

<?php
if(isset(_POST['submit'])){
$name = htmlspecialchars($_POST['name']); 
$subject = htmlspecialchars($_POST['subject']); 
$from = htmlspecialchars($_POST['mail']);
$message = htmlspecialchars($_POST['message']); 

$to = "[email protected]"; 
$headers = "From:" . $from; 
$txt = "You have received an email from".$name.".\n\n.$message;
}

{
     if ( mail($to, $subject, $message, $headers)); 
      echo("Message successfully sent");
    } else {
      echo("Message sending failed...");
    }
?>

using code blocks in your posts will help make php more legible.

[code]<?php ?>[/code]

i suggest that you start writing php code like old basic programs: line-by-line. I also recommend using a syntax highlighting editor. Then, maybe, you will be able to see your errors.

<?php
if(isset(_POST['submit'])) {
$name = htmlspecialchars($_POST['name']);
$subject = htmlspecialchars($_POST['subject']);
$from = htmlspecialchars($_POST['mail']);
$message = htmlspecialchars($_POST['message']);
$to = "[email protected]";
$headers = "From:" . $from;
$txt = "You have received an email from".$name.".\n\n.$message;
}
{
if ( mail($to, $subject, $message, $headers));
echo("Message successfully sent");
}
else { echo("Message sending failed...");
}
?>

take a closer look at your conditional statements. highlighted in red text.

Tested it, when I click send, nothing happens.

And if you notice when the code is highlighted, something isn’t quite right. Look at the code and you should see the problem.

Turn on error notifications when you are developing to tell you problems…

1 Like
Sponsor our Newsletter | Privacy Policy | Terms of Service