PHP Email Form Sends Blank Emails HELP!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bluboxwe
Forum Newbie
Posts: 1
Joined: Sat Feb 27, 2010 8:52 pm

PHP Email Form Sends Blank Emails HELP!

Post by bluboxwe »

I've tried for hours to try and figure out why I receive blank emails when my online form is filled out. I'm reaching out! I need help. Below is the code that I am using. What am I doing wrong?

Code: Select all

<?php
 
/* Subject and Email Variables */
 
    $emailSubject = 'Contact Information Submit';
    $webMaster = 'paige@bluboxwebdesign.com';
    
/*Gathering Data Variables */
 
    $emailField = $_POST['email'];
    $nameField = $_POST['name'];
    $phoneField = $_POST['phone'];
    $commentsField = $_POST['comments'];
    
    $body = <<<EOD
<br><hr><br>
Email: $email <br>  
Name: $name <br>
Phone Number: $phone <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><!-- InstanceBegin template="/Templates/thanks.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<!-- InstanceBeginEditable name="doctitle" -->
<title>Thank You | Time Machine Analytics</title>
<!-- InstanceEndEditable -->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<!-- InstanceBeginEditable name="head" -->
<style type="text/css">
<!--
a img {
    border-top-style: none;
    border-right-style: none;
    border-bottom-style: none;
    border-left-style: none;
}
-->
</style>
<!-- InstanceEndEditable -->
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<!-- Save for Web Slices (thanks.psd) -->
<table width="1194" height="886" border="0" align="center" cellpadding="0" cellspacing="0" id="Table_01">
    <tr>
        <td colspan="11">
            <img src="images/thanks_011.jpg" width="1194" height="34" alt=""></td>
    </tr>
    <tr>
        <td rowspan="6">
            <img src="images/thanks_022.jpg" width="146" height="851" alt=""></td>
        <td colspan="3"><!-- InstanceBeginEditable name="EditRegion1" --><a href="index.html"><img src="images/thanks_033.jpg" width="278" height="138" alt=""></a><!-- InstanceEndEditable --></td>
        <td colspan="7" rowspan="2">
            <img src="images/thanks_044.jpg" width="770" height="158" alt=""></td>
    </tr>
    <tr>
        <td colspan="3">
            <img src="images/thanks_055.jpg" width="278" height="20" alt=""></td>
    </tr>
    <tr>
        <td colspan="2" rowspan="2">
            <img src="images/thanks_066.jpg" width="259" height="648" alt=""></td>
        <td colspan="2"><!-- InstanceBeginEditable name="EditRegion2" --><a href="index.html"><img src="images/thanks_077.jpg" width="68" height="41" alt=""></a><!-- InstanceEndEditable --></td>
        <td><!-- InstanceBeginEditable name="EditRegion3" --><a href="abouttma.html"><img src="images/thanks_088.jpg" width="90" height="41" alt=""></a><!-- InstanceEndEditable --></td>
        <td><!-- InstanceBeginEditable name="EditRegion4" --><a href="business_solutions.html"><img src="images/thanks_099.jpg" width="173" height="41" alt=""></a><!-- InstanceEndEditable --></td>
        <td colspan="2"><!-- InstanceBeginEditable name="EditRegion5" --><a href="featuredreports.html"><img src="images/thanks_1010.jpg" width="124" height="41" alt=""></a><!-- InstanceEndEditable --></td>
        <td><!-- InstanceBeginEditable name="EditRegion6" --><a href="contact.php"><img src="images/thanks_1111.jpg" width="114" height="41" alt=""></a><!-- InstanceEndEditable --></td>
        <td rowspan="4">
            <img src="images/thanks_1212.jpg" width="220" height="693" alt=""></td>
    </tr>
    <tr>
        <td colspan="7">
            <img src="images/thanks_1313.jpg" width="569" height="607" alt=""></td>
    </tr>
    <tr>
        <td rowspan="2">
            <img src="images/thanks_1414.jpg" width="222" height="45" alt=""></td>
        <td colspan="6"><!-- InstanceBeginEditable name="EditRegion7" --><a href="http://www.bluboxwebdesign.com"><img src="images/thanks_1515.jpg" width="477" height="29" alt=""></a><!-- InstanceEndEditable --></td>
        <td colspan="2" rowspan="2">
            <img src="images/thanks_1616.jpg" width="129" height="45" alt=""></td>
    </tr>
    <tr>
        <td colspan="6">
            <img src="images/thanks_1717.jpg" width="477" height="16" alt=""></td>
    </tr>
    <tr>
        <td>
            <img src="images/spacer.gif" width="146" height="1" alt=""></td>
        <td>
            <img src="images/spacer.gif" width="222" height="1" alt=""></td>
        <td>
            <img src="images/spacer.gif" width="37" height="1" alt=""></td>
        <td>
            <img src="images/spacer.gif" width="19" height="1" alt=""></td>
        <td>
            <img src="images/spacer.gif" width="49" height="1" alt=""></td>
        <td>
            <img src="images/spacer.gif" width="90" height="1" alt=""></td>
        <td>
            <img src="images/spacer.gif" width="173" height="1" alt=""></td>
        <td>
            <img src="images/spacer.gif" width="109" height="1" alt=""></td>
        <td>
            <img src="images/spacer.gif" width="15" height="1" alt=""></td>
        <td>
            <img src="images/spacer.gif" width="114" height="1" alt=""></td>
        <td>
            <img src="images/spacer.gif" width="220" height="1" alt=""></td>
    </tr>
</table>
<!-- End Save for Web Slices -->
</body>
<!-- InstanceEnd --></html>
EOD;
echo "$theResults";
?>
---
s.dot - Please use [ php ] and [ /php ] tags when posting php code.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Re: PHP Email Form Sends Blank Emails HELP!

Post by s.dot »

Are you getting any mail at all?

This part could be your problem, if you are receiving mail without the variables filled in:

Code: Select all

 $emailField = $_POST['email'];
     $nameField = $_POST['name'];
    $phoneField = $_POST['phone'];
     $commentsField = $_POST['comments'];
    
     $body = <<<EOD
 <br><hr><br>
 Email: $email <br> 
 Name: $name <br>
 Phone Number: $phone <br>   
 Comments: $comments <br>   
 EOD;    
in $body... $email should be $emailField, $name should be $nameField.. etc.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Re: PHP Email Form Sends Blank Emails HELP!

Post by Benjamin »

:arrow: Moved to PHP - Code
Post Reply