Contact.php

Hi,
Trying to complete a contact page as part of a webpage. When I click send it transfers to a blank page. Not sure where went wrong.

contactform.php

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

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

if(from($mailto,$subject,$txt,$headers));
{
echo "<b>Message successfully sent</b>"; 
}
else { echo"<b>Message sending failed...</b>";
}
?>

Thank You

Could you place your code between code tags please?
Did you turn on the php error messages?

ini_set('display_errors', 1);
error_reporting(E_ALL);

// the rest of your code

You aren’t doing the redirection there. That means you probably have an action in your form that sends you somewhere else, or there is more to that script that you did not post.

<html>
<head>
<style type="text/css">
body{font-family:arial;
}
table{font-size:100%;width:100%;background-color:#000000;}
a{color:#ffffff;text-decoration:none;font:bold}
a:hover{color:#ffffff;}
td.menu{background-color:#000000;}
table.menu
{
font-size:100%;
position:absolute;
visibility:hidden;
}
.center
{
margin:auto;
width:60%;
background-color:#FFFFFF;
}
</style>
<script type="text/javascript">
function showmenu(elmnt)
{
document.getElementById(elmnt).style.visibility="visible";
}
function hidemenu(elmnt)
{
document.getElementById(elmnt).style.visibility="hidden";
}
</script>
</head>
<body>
<br>
<br>
<br>
<br>
<div class="center">
<p>
<div align="center"><img src="bloggoneitbanner.jpg"></div>  
<br>
<table>  
<td onmouseover="showmenu('home')" onmouseout="hidemenu('home')">
<a href="http://bloggoneit.net/" target="_blank">Home</a>    
<table class="menu" id="home" width="120">
</table>
</td>
<td onmouseover="showmenu('about')" onmouseout="hidemenu('about')">
<a href="about.html" target="_blank">About</a>   
<table class="menu" id="about" width="120">
</table>
</td>
<td onmouseover="showmenu('blog')" onmouseout="hidemenu('blog')">
 <a href="blog.html" target="_blank">Blog</a>  
  <table class="menu" id="blog" width="120">
</table>
</td>
<td onmouseover="showmenu('contact')" onmouseout="hidemenu('contact')">
<a href="contact.php" target="_blank">Contact</a>          
<table class="menu" id="contact" width="120">
</table>
</td>
<td onmouseover="showmenu('services')" onmouseout="hidemenu('services')">
<a href="services.html" target="_blank">Services</a>          
<table class="menu" id="contact" width="120">
</table>
</td>
</table>
<br>
<br>
<br>
<br>

<br>
<br>
<br>
<br>
<br>
<br>
<br>
<div align="center">
<form action="contactform.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="Comments..."></textarea>
<br />
<br />
<input type="image" src="sendbutton.jpg" name="submit"> 
</form>
<br>
<br>
<br>
<br>
<hr>
<h3>Created and designed by</h3><br>
<img src="G9banner.jpg" width="85" height="85" border="0"></div>
</p>
</div>
</body>  
</html>

Apologies.

And there it is.

Also, you really need to look into modern web design, there is no reason for tables as layouts or all of those break lines in a document.

The above code is wrong. It should be:

$txt = "You have received an email from {$name}\n\n{$message}";

But as you are outputting to a web page, better is:

$txt = "You have received an email from {$name}<br /><br />{$message}";
  1. It isn’t wrong, but using string interpolation is cleaner.
  2. It’s for an email body, so the first is newline character is correct, not the breakline return.

By wrong, I meant that the two new line characters were outside the double quotes. They would need to be within the double quotes.

It was missing the end set of quotes, which wasn’t as clear. String interpolation is better for readability sake, agree.

When I enter the information, it still transfers to a blank screen. Not sure.

That’s because you have a fatal error as mentioned above.

Sponsor our Newsletter | Privacy Policy | Terms of Service