PHP email sent half blank?

  • ancientmysts
  • Newbie
  • Newbie
  • ancientmysts
  • Posts: 9

Post 3+ Months Ago

First time poster, so this would be my introduction as well. Self taught HTML (so my code is usually a mess I'm sure). My boss knows that I know a little bit about websites, so he asked me to build one for him. He has a small construction company. What started out as a simple task, got bigger and bigger and I feel a little over my head, but still trying to please the boss, as he's a personal friend as well.

He asked me to create a form on the website where users could type out information to receive an estimate or to send in a testimonial that would kick out to an email. I looking into it saw that PHP was the way to go. I hunted around and found a tutorial on how to do it, which was from tutvid on youtube. Finally to the point where I'm about ready to go live with the site and tested my code.

I would receive the body of my email, the text that I put in that the users input follows, but the text the user puts in comes in blank every time. I've searched the forums and only got 2 threads, 1 of which wasn't what I was looking for, the other was just bad punctuation on the PHP code, and his was fixed. If someone could help me out here it would be appreciated. Below is the code I'm using.

Code: [ Select ]
<?php

/* subject and email variables */

  $emailSubject = 'Customer sending in a testimonial';
  $webMaster = 'NOT ALLOWED TO POST EXTERNAL LINKS';
  
/* gathering data variables */

  $nameField = $_POST['name'];
  $locationField = $_POST['location'];
  $servicesField = $_POST['services'];
  $experienceField = $_POST['experience'];
  
  $body = <<<EOD
<br><hr><br>
Name: $name <br>
Location: $location <br>
Services Received: $services <br>
Overall Experience: $experience <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
/* I have put a thank you page here, just didn't want to include all of that code */
EOD;
echo "$theResults";

?>
  1. <?php
  2. /* subject and email variables */
  3.   $emailSubject = 'Customer sending in a testimonial';
  4.   $webMaster = 'NOT ALLOWED TO POST EXTERNAL LINKS';
  5.   
  6. /* gathering data variables */
  7.   $nameField = $_POST['name'];
  8.   $locationField = $_POST['location'];
  9.   $servicesField = $_POST['services'];
  10.   $experienceField = $_POST['experience'];
  11.   
  12.   $body = <<<EOD
  13. <br><hr><br>
  14. Name: $name <br>
  15. Location: $location <br>
  16. Services Received: $services <br>
  17. Overall Experience: $experience <br>
  18. EOD;
  19.     $headers = "From: $email\r\n";
  20.   $headers .= "Content-type: text/html\r\n";
  21.   $success = mail($webMaster, $emailSubject, $body, $headers);
  22.   
  23. /* results rendered as html */
  24.     $theResults = <<<EOD
  25. /* I have put a thank you page here, just didn't want to include all of that code */
  26. EOD;
  27. echo "$theResults";
  28. ?>


The email I receive ends up looking like this....

Name:
Services:
Location:
Overall Experience:

...with no responses. Any and all help would be appreciated, and I thank you for your time and help in advance.
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • ancientmysts
  • Newbie
  • Newbie
  • ancientmysts
  • Posts: 9

Post 3+ Months Ago

Ok, so I kept hunting and figured out the problem. In the tutorial it was a bit off in the explanation. I have no clue as to why they had the "Field" after each code, but that turned out to be my problem. I'm showing the new code in case someone else comes here with the same issue, they also will have an answer.

Code: [ Select ]
<?php

  /* subject and email variables */

  $emailSubject = 'Customer sending in a testimonial';
  $webMaster = 'NOT ALLOWED TO POST EXTERNAL LINKS';
 
  /* gathering data variables */

  $name = $_POST['name'];
  $location = $_POST['location'];
  $services = $_POST['services'];
  $experience = $_POST['experience'];

  $body = <<<EOD
<br><hr><br>
Name: $name <br>
Location: $location <br>
Services Received: $services <br>
Overall Experience: $experience <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
/* I have put a thank you page here, just didn't want to include all of that code */
EOD;
echo "$theResults";

?>
  1. <?php
  2.   /* subject and email variables */
  3.   $emailSubject = 'Customer sending in a testimonial';
  4.   $webMaster = 'NOT ALLOWED TO POST EXTERNAL LINKS';
  5.  
  6.   /* gathering data variables */
  7.   $name = $_POST['name'];
  8.   $location = $_POST['location'];
  9.   $services = $_POST['services'];
  10.   $experience = $_POST['experience'];
  11.   $body = <<<EOD
  12. <br><hr><br>
  13. Name: $name <br>
  14. Location: $location <br>
  15. Services Received: $services <br>
  16. Overall Experience: $experience <br>
  17. EOD;
  18.   $headers = "From: $email\r\n";
  19.   $headers .= "Content-type: text/html\r\n";
  20.   $success = mail($webMaster, $emailSubject, $body, $headers);
  21.  
  22. /* results rendered as html */
  23.   $theResults = <<<EOD
  24. /* I have put a thank you page here, just didn't want to include all of that code */
  25. EOD;
  26. echo "$theResults";
  27. ?>

Post Information

  • Total Posts in this topic: 2 posts
  • Users browsing this forum: No registered users and 71 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.