Solved

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

Posted on 2009-03-31
7
636 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
  • 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
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now