Link to home
Start Free TrialLog in
Avatar of neonate928
neonate928

asked on

PHP form sends email but subject, message header etc.. are blank

I have a contact us form I am trying to get to work. My server supports PHP so that is what I am using. This is my first attempt to do something like this so I am starting small, once I get this contact us form to work I want to create an online application form. Anywho...

I recieve emails however, the subject, message, headers are all blank in the recieved email. How can I fix this? the code for both the form and php are below I am not doing any validation as of yet until I get this to work.
HTML:
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="CSS/layout.css">
<title>RN Resources, LLC</title>
</head>
 
<body class="oneColFixCtrHdr">
 
<div id="container">
  <div id="header">
    <!--Header jpg will display here.-->
    <div id="navMenu">
    			<ul>
        			<li><a href="index.html" class="home"> </a></li>
                    <li><a href="faq.html" class="faq"> </a></li>
        			<li><a href="about.html" class="about"> </a></li>
    			</ul>
    <!-- end #navMenu --></div>
    <!-- end #header --></div>
  <div id="mainContent">
  	<div id="aboutimage">
    	<!-- about us jpg will display here -->
    <!-- end #aboutimage --></div>
    <div id="about">
    	<p>We are a professional nurse staffing agency, working in partnership with nationwide healthcare facilities, nurses and CNA's. We are setting the standard in the travel nursing industry, do to our quality, dedication and experience to service and healthcare excellence. Our primary mission is to always provide the highest quality to our nurses and customers - achieving this goal day in and day out by our experienced and professional staff.</p>
        <p>Our recruiters are becoming the best in the industry. When you first join our team your recruiter will be with you from day one, becoming your primary link between you and the potential healthcare facilities you want. Your recruiter strives to the highest standard to find you the salary you desire, the shifts you want to work in the places you wish to travel. Our recruiters are the distinctive link that sets us apart from the rest.</p>
        <p>We are setting the  bar to innovate the travel nursing industry. That is why we focus on the one-on-one touch with each and everyone of our nurses, and it is this approach that distinguishes us from our competitors. We believe that our unique approach to our nurses is the foundation to our growth and we continually thrive on the individual character, work ethic, and desire each of our nurses brings to the table.</p>
        <p>We are committed to excellence in every aspect within the healthcare community.</p> 
    <!-- end #about --></div>
    <div id="verspliter">
    	<!-- spliter jpg will display here -->
    <!-- end #verspliter --></div>
    <div id="contactimage">
     	<!-- contact us jpg will display here -->
    <!-- end #contactimage --></div>
    <div id="contactinfo">
        <p>Phone: 928-775-0903</p>
        <p>Email: rnresources@rnresources.com</p>
        <table width = "340" border="0" align="center" celpadding="3" cellspacing="1">
        	<tr>
            	<td><form name="contactForm" method="post" action="contactus.php">
                <table width="100%" border="0" cellspacing="1" cellpadding="3">
                    <tr>
                    	<td width="16%">Name</td>
                        <td width="2%">:</td>
                        <td width="82%"><input name="name" type="text" id="name" size="25" /></td>
                    </tr>
                    <tr>
                    	<td>Email</td>
                        <td>:</td>
                        <td><input name="customer_mail" type="text" id="cusomter_mail" size="25" /></td>
                    </tr>
                    <tr>
                    	<td>Subject</td>
                        <td>:</td>
                        <td><input name="subject" type="text" id="subject" size="25"></td>
                    </tr>
                    <tr align="justify">
                    	<td>Message</td>
                        <td>:</td>
                        <td><textarea name="body" cols="25" rows="8" id="body"></textarea></td>
                    </tr>
                    <tr>
                    	<td>&nbsp;</td>
                        <td>&nbsp;</td>
                        <td><input type="submit" name="Submit" value="Submit" /></td>
                    </tr>
               </table>
               </form>
               </td>
               </tr>
      </table>
    <!-- endd #contactinfo --></div>
  <!-- end #mainContent --></div>
  <div id="footer">
    <!--Footer jpg will display here.-->
    <p>Copyright © 2009-2010. RN Resources, LLC all rights reserved.</p>
  <!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>
 
----------------------------------
 
PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="CSS/layout.css">
<title>RN Resources, LLC</title>
</head>
 
<body class="oneColFixCtrHdr">
 
<div id="container">
  <div id="header">
    <!--Header jpg will display here.-->
    <div id="navMenu">
    			<ul>
        			<li><a href="index.html" class="home"> </a></li>
                    <li><a href="faq.html" class="faq"> </a></li>
        			<li><a href="about.html" class="about"> </a></li>
    			</ul>
    <!-- end #navMenu --></div>
    <!-- end #header --></div>
  <div id="mainContent">
  <?php
  	$subject="$subject";
	$message="$body";
	$mail_from="$customer_mail";
	$header="from: $name <$mail_from>";
	
	$to="neonate928@hotmail.com";
	
	$send_contact=mail($to,$subject,$message,$header);
	
	if($send_contact) {
	echo "Information Recieved";
	}
	else {
	echo "ERROR";
	}
  ?>  	
  <!-- end #mainContent --></div>
  <div id="footer">
    <!--Footer jpg will display here.-->
    <p>Copyright © 2009-2010. RN Resources, LLC all rights reserved.</p>
  <!-- end #footer --></div>
<!-- end #container --></div>
</body>
</html>

Open in new window

Avatar of pmessana
pmessana

You need to capture the POST data; you are referencing a variable that will not be defined on that page.

Change this block
        $subject="$subject";
        $message="$body";
        $mail_from="$customer_mail";
        $header="from: $name <$mail_from>";

To:
$subject=$_POST['subject'];
$message=$_POST['body'];
$mail_from=$_POST['customer_email']";
$header="from: $_POST['name'] <$_POST['mail_from']>";

Open in new window

Try addressing the POST variables in another way. Here is an example PHP code snippet.
 <?php
        $subject= $_POST['subject'];
        $message= $_POST['body'];
        $mail_from= $_POST['customer_mail'];
        $header="from: ".$_POST['name']." <".$_POST['mail_from'].">";
        
        $to="neonate928@hotmail.com";
        
        $send_contact=mail($to,$subject,$message,$header);
        
        if($send_contact) {
        echo "Information Recieved";
        }
        else {
        echo "ERROR";
        }
  ?>

Open in new window

Avatar of neonate928

ASKER

Ok we are one step closer. The subject is now filled in, however there is still no body (message) or header within the recieved email.
ASKER CERTIFIED SOLUTION
Avatar of captaincagemen
captaincagemen
Flag of Netherlands image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Captaincagemen:
The new header you provided did not work so I improvised and used one the first one you provided in another comment. Now everything is working :) YAHOO!
Thank you!
Great! I indeed forget an " in the last header, should be:
$header="from: ".$_POST['name']."<".$_POST['customer_mail'].">";

Open in new window