# Contactform php

**URL:** <https://forum.freecodecamp.org/t/contactform-php/347727>\
**Category:** General\
**Created:** [February 5, 2020, 5:38pm UTC](https://forum.freecodecamp.org/t/contactform-php/347727 "2020-02-05T17:38:42Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![phkatz](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@phkatz](https://forum.freecodecamp.org/u/phkatz)\
**Post date:** [February 5, 2020, 5:38pm UTC](https://forum.freecodecamp.org/t/contactform-php/347727/1 "2020-02-05T17:38:42Z")

</div>

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

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

$mailto = "keith.williams@bloggoneit.net"; 
$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

---

<div class="post-metadata">

**Author:** ![phkatz](https://avatars.discourse-cdn.com/v4/letter/p/ee59a6/32.png) [@phkatz](https://forum.freecodecamp.org/u/phkatz)\
**Post date:** [February 5, 2020, 7:10pm UTC](https://forum.freecodecamp.org/t/contactform-php/347727/4 "2020-02-05T19:10:35Z")

</div>

Hi,  
That’s how it was written.

````auto
<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)

 It would be **from**
````

---

<div class="post-metadata">

**Author:** ![FatmaNagori](https://avatars.discourse-cdn.com/v4/letter/f/ba9def/32.png) [@FatmaNagori](https://forum.freecodecamp.org/u/FatmaNagori)\
**Post date:** [February 5, 2020, 7:56pm UTC](https://forum.freecodecamp.org/t/contactform-php/347727/5 "2020-02-05T19:56:56Z")

</div>

Your code has many mistakes .

1. you have to close your first if statement `if(isset($_POST['submit'])){` before `?>`.
2. in your `$txt` variable you need to close double quote i.e.

```auto
$txt = "You have received an email from".$name."\n\n".$message;

```

1. in you second if you use a `from()` what it do .
2. you put a semicolon in if statement .

Always remember one thing in php we use a semicolon to end statement.  
explain your `form()` if you want to fix issue.

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [June 1, 2021, 7:36pm UTC](https://forum.freecodecamp.org/t/contactform-php/347727/6 "2021-06-01T19:36:54Z")

</div>

Closed on June 1, 2021, 7:36pm UTC


