Solved

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

Posted on 2009-03-31
7
644 Views
Last Modified: 2012-05-06
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

0
Comment
Question by:neonate928
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
7 Comments
 
LVL 9

Expert Comment

by:pmessana
ID: 24033553
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

0
 
LVL 2

Expert Comment

by:captaincagemen
ID: 24033568
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

0
 

Author Comment

by:neonate928
ID: 24033662
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.
0
Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

 
LVL 2

Accepted Solution

by:
captaincagemen earned 500 total points
ID: 24033707
Mmm.. ok i found the header fault (see code snippet) and maby you should try to change to name of "body". Rename it to usermessage(see snippet)
<textarea name="usermessage" cols="25" rows="8" id="usermessage"></textarea>
 
 <?php
        $subject= $_POST['subject'];
        $message= $_POST['usermessage'];
        $mail_from= $_POST['customer_mail'];
        $header="from: ".$_POST['name'].<".$_POST['customer_mail'].">";
        
        $to="neonate928@hotmail.com";
        
        $send_contact=mail($to,$subject,$message,$header);
        
        if($send_contact) {
        echo "Information Recieved";
        }
        else {
        echo "ERROR";
        }
  ?>

Open in new window

0
 

Author Comment

by:neonate928
ID: 24034845
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!
0
 

Author Closing Comment

by:neonate928
ID: 31565053
Thank you!
0
 
LVL 2

Expert Comment

by:captaincagemen
ID: 24036360
Great! I indeed forget an " in the last header, should be:
$header="from: ".$_POST['name']."<".$_POST['customer_mail'].">";

Open in new window

0

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

730 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question