logo-dw

Go Back   Dreamweaver Club Forums > Hand Coders Forum > PHP
Register FAQ Members List Search Today's Posts Mark Forums Read

Reply
 
Thread Tools Display Modes
Old 11-08-2014, 02:57 AM   #1
cellopoet
 
Join Date: Nov 2014
Posts: 3
Default PHP contact form sending blank emails

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>
cellopoet is offline   Reply With Quote
Old 11-08-2014, 03:49 AM   #2
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,176
Default

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
Code:
<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
Code:
<?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;


?>
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 11-08-2014, 05:42 PM   #3
cellopoet
 
Join Date: Nov 2014
Posts: 3
Default

@edbr, I tried your script and now I am not getting any email at all. Any other suggestions? It seems like my code should work. What am I missing?
cellopoet is offline   Reply With Quote
Old 11-10-2014, 09:05 AM   #4
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,176
Default

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
Code:
<?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);

?>
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 11-10-2014, 07:10 PM   #5
cellopoet
 
Join Date: Nov 2014
Posts: 3
Default Problem solved!

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!!
cellopoet is offline   Reply With Quote
Old 11-11-2014, 01:01 AM   #6
edbr
edbr's Avatar
 
Join Date: Aug 2005
Location: Bali
Posts: 11,176
Default

good one, sorry i couldnt help more but you did exactly what i would have done
__________________
If you're happy and you know it shake your meds!
different style links examples

Flight / Hotel search
Free script download
Bali Villas
edbr is offline   Reply With Quote
Old 03-10-2015, 04:21 PM   #7
ragortue
 
Join Date: Mar 2015
Posts: 15
Default

Not worth the time investigating. But thank you for your pointer below cellopoet.

Quote:
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.
ragortue is offline   Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 03:10 AM.


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2017, vBulletin Solutions, Inc.
Copyright 2006 DreamweaverClub.com