PDA

View Full Version : PHP contact form sending blank emails


cellopoet
11-08-2014, 01:57 AM
I am completely new to php, so I am having trouble finding a solution to my problem. I created a contact form and used a downloaded php file that matches my form. It seems to work except for the fact that when the form is filled out and submitted, the email it sends leaves all the fields blank:
Name:
Email:
Comments:

I have both the html and php files uploaded to my site root. I have not done anything on the server side (I use hostgator) and honestly would not even know where to begin if the problem is on that end.

Any help for this complete noob would be greatly appreciated!!!!:)

Here is the php I am using:

<?php

/* Email Variables */
$emailSubject = 'contactformprocess!';
$webMaster = 'my email is here';

/* Data Variables */
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];

$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Comments: $comments <br>
EOD;
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body,
$headers);

/* Results rendered as HTML */
$theResults = <<<EOD
<html>
<head>
<title>sent message</title>
<meta http-equiv="refresh" content="3;URL=http://www.lindarife.com/index.html">
<style type="text/css">
<!--
body {
background-color: #555555;
font-family: gruppo;
font-size: 20px;
font-style: normal;
line-height: normal;
font-weight: normal;
color: #FFFFFF;
text-decoration: none;
padding-top: 200px;
margin-left: 150px;
width: 800px;
}
-->
</style>
</head>
<div align="center">Thank you for contacting me. You will hear back from me soon!</div>
</div>
</body>
</html>
EOD;
echo "$theResults";
?>

And here is the html for my form:

<form action="contactformprocess.php" method="post" enctype="text/plain" id="contact">
<label for="name">Name:</label>
<br>
<input name="name" type="text" required id="name" form="contact" autocomplete="on">
<br>
<label for="email">E-mail:</label>
<br>
<input name="email" type="email" required id="email" form="contact" placeholder="name@domain.com" autocomplete="on">
<br><label for="comments">Message:</label><br><textarea name="comments" required id="comments" form="contact" placeholder="Write your message here. You can expand this text area by clicking and dragging the lower right corner."></textarea><br>
<input name="submit" type="submit" value="Submit"></form>

edbr
11-08-2014, 02:49 AM
right some thing odd there. im a bit time strapped but heres a working stripped don version. il try and resurrest it later if i have time

html
<form action="contactformprocess.php" method="post" id="contact">
<label for="name">Name:</label>
<br>
<input name="name" type="text" required id="name"
<br>
<label for="email">E-mail:</label>
<br>
<input name="email" type="email" required id="email">
<br><label for="comments">Message:</label><br><textarea name="comments" required id="comments"
></textarea><br>
<input name="submit" type="submit" value="Submit"></form>


php
<?php

/* Email Variables */
$emailSubject = 'contactformprocess!';
$webMaster = 'lindarifemusic@gmail.com';
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";


/* Data Variables */
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];


echo





$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Comments: $comments <br>
EOD;


?>

cellopoet
11-08-2014, 04:42 PM
@edbr, I tried your script and now I am not getting any email at all. :confused: Any other suggestions? It seems like my code should work. What am I missing?

edbr
11-10-2014, 08:05 AM
really? i tested it locally but must admit i was in a rush , ill try to look at it again later. oh hang on i have missed half of it sorry
<?php

/* Email Variables */
$emailSubject = 'contactformprocess!';
$webMaster = 'lindarifemusic@gmail.com';
$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";


/* Data Variables */
$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];

$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Comments: $comments <br>
EOD;
$success = mail($webMaster, $emailSubject, $body,
$headers);

?>

cellopoet
11-10-2014, 06:10 PM
I've finally fixed the problem. It actually doesn't seem to have been a problem with the php, though. I used your stripped down php and html and that worked. Then, to figure out the precise problem, I used the process of elimination. I reverted to my original php and it was still working, so the problem had to be in the html. I then added some of the tags I had back to the html, one thing at a time, so I could maintain my placeholder text, etc. Now, I'm back to what I had originally, but I have gotten rid of the enctype="text/plain", form="contact", and autocomplete="on" tags. I'm not sure which one exactly was causing the problem, but the form works the way I want now, so I don't feel the need to further investigate. Autocomplete must be a default because even though I eliminated it, it still does autocomplete. I have a feeling the problem was enctype="text/plain" or form="contact".

Thanks for your help!! :D

edbr
11-11-2014, 12:01 AM
good one, sorry i couldnt help more but you did exactly what i would have done :)

ragortue
03-10-2015, 03:21 PM
Not worth the time investigating. But thank you for your pointer below cellopoet. https://imagicon.info/cat/6-4/1.gif

Now, I'm back to what I had originally, but I have gotten rid of the enctype="text/plain", form="contact", and autocomplete="on" tags.