Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
I have a predefined contact form that I m trying to pair with a php mail sender Hower when I sent the form, my email address received well the form but the content of the message doesn't not appear. Below is the details:
 
Contact form
<h4>Contact Form:</h4>
                           <form id="contact-form" method="post" action="submit.php">
                               <fieldset>
                                   <label><input name="email" value="Email" onBlur="if(this.value=='') this.value='Email'" onFocus="if(this.value =='Email' ) this.value=''" /></label>
                                   <label><input name="subject" value="Subject" onBlur="if(this.value=='') this.value='Subject'" onFocus="if(this.value =='Subject' ) this.value=''" /></label>
                                   <textarea   onBlur="if(this.value=='') this.value='Message'" onFocus="if(this.value =='Message' ) this.value=''">Message</textarea>
                                   <div class="buttons">
                                       <a href="#" onClick="document.getElementById('contact-form').reset()">Clear</a>
                                       <a href="#" onClick="document.getElementById('contact-form').submit()">Send</a>
                                   </div>
                               </fieldset>
                           </form>
 
Submit form
 
<?php
 
// Contact subject
$subject ="$Subject";
 
// Details
$message="$Message";
 
// Mail of sender
$mail_from="$Email";
//form data
    $Subject = $_POST['subject'];
    $Email = $_POST['email'];
    $Message = $_POST['message'];
 
    //sumbission data
    $ipaddress = $_SERVER['REMOTE_ADDR'];
    $date = date('d/m/Y');
    $time = date('H:i:s');
//send email if all is ok

        $headers = "From: $Email" . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
// From
$emailbody = "<p>You have recieved a new message from the enquiries form on your website.</p>
                      <p><strong>Email Address: </strong> {$Email} </p>
                      <p><strong>Enquiry: </strong> {$Subject} </p>
                      <p><strong>Message: </strong> {$Message} </p>
                      <p>This message was sent from the IP Address: {$ipaddress} on {$date} at {$time}</p>";
$header="from: $Email <$Message>";
 
// Enter your email address
$to ='exemple@exemple.com';
$send_contact=mail("exemple@exemple.com","New Enquiry",$emailbody,$headers);
 
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>
 
Test account result
You have recieved a new message from the enquiries form on your website.
 
Email Address: testtome@test.com
 
Enquiry: Web service
 
Message:
 
This message was sent from the IP Address: 101.229.203.44 on 04/01/2013 at 00:23:15
As you can see the message content is not showing up. Please help.
Posted 3-Jan-13 5:43am
Comments
Sergey Alexandrovich Kryukov at 3-Jan-13 15:06pm
   
Actually, not "PHP form", "HTML form". One your problem is there.
—SA
Anselmo santos at 3-Jan-13 15:22pm
   

Contact Form:

<form id="contact-form" method="post" action="lightbox/submit.php">
<fieldset>
<label><input name="email" value="Email" onBlur="if(this.value=='') this.value='Email'" önFocus="if(this.value =='Email' ) this.value=''" /></label>
<label><input name="subject" value="Subject" onBlur="if(this.value=='') this.value='Subject'" önFocus="if(this.value =='Subject' ) this.value=''" /></label>
<textarea name="message" id="message" value="message" onBlur="if(this.value=='message') this.value='message'" önFocus="if(this.value =='message' ) this.value='message'">Message</textarea>
<!--<textarea name="message" id="message" onBlur="if(this.value=='') this.value=''" önFocus="if(this.value =='' ) this.value=''"></textarea>-->
 

<div class="buttons">
Clear
Send
</div>
</fieldset>
</form>
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

You forgot to mention the name "message" in your form, that's why.
 
In your case, in you HTML form, you should have added the attribute name="message" to your textarea element. Will work.
 
—SA
  Permalink  
v2
Comments
Anselmo santos at 3-Jan-13 15:12pm
   
I did add the name="message" but i still have the same issue
Sergey Alexandrovich Kryukov at 3-Jan-13 15:17pm
   
Hm. Can I see that fragment of HTML?
And, as I can see, this is not your only problem. I'm going to continue. But first, please show what you got.
—SA
Anselmo santos at 4-Jan-13 8:30am
   
I reposted my html code. I have added the name tag but it didnt solve the issue.
I am all new to this area. I also heard I need to improve the php code to avoid spam.
Any idea on how to do this too?
Sergey Alexandrovich Kryukov at 4-Jan-13 8:57am
   
I cannot see what else is wrong with unarmed eye. You may need some debugging...
—SA
Anselmo santos at 3-Jan-13 15:55pm
   
Here is the contact form:
<form id="contact-form" method="post" action="lightbox/submit.php">
<fieldset>
<label><input name="email" value="Email" onBlur="if(this.value=='') this.value='Email'" önFocus="if(this.value =='Email' ) this.value=''" /></label>
<label><input name="subject" value="Subject" onBlur="if(this.value=='') this.value='Subject'" önFocus="if(this.value =='Subject' ) this.value=''" /></label>
<textarea name="message" id="message" value="message" onBlur="if(this.value=='message') this.value='message'" önFocus="if(this.value =='message' ) this.value='message'">Message</textarea>
<!--<textarea name="message" id="message" onBlur="if(this.value=='') this.value=''" önFocus="if(this.value =='' ) this.value=''"></textarea>-->
 

<div class="buttons">
Clear
Send
</div>
</fieldset>
</form>
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Anselmo Santos wrote:
I also heard I need to improve the PHP code to avoid spam. Any idea on how to do this too?
This is exactly what I want to to tell you next. This is not spam. This is worse. Through your code, it's easy to turn your host into a zombie sending spam or other malicious content. This is so easy that it's even funny. I personally faced with this kind of exploit. Fortunately, this is also relatively easy to prevent, but it requires close attention. I'll explain it. Just see my past answer where I explained it:
unable to send mail , it showing the error in below code .[^].
 
If something is not clear, please ask your questions, as this is an important aspect.
 
—SA
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

You need to change <textarea name="message" ...xxx...="">
 
you must give name to textarea to recognize it as a content.
 
If you give its name as "message" you can read this by using $_GET['message'] or $_POST['message'] or $_REQUEST['message'] Accoring to the form method. $_REQUEST can be used for both POST & GET method. Hope you understand your fault in above comments. So I'm just giving additional details about it Smile | :) </textarea>
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 344
1 Nirav Prabtani 252
2 Abhinav S 220
3 Dave Kreskowiak 155
4 Pikoh 140
0 OriginalGriff 7,545
1 Sergey Alexandrovich Kryukov 6,757
2 Maciej Los 3,909
3 Peter Leow 3,693
4 CHill60 2,712


Advertise | Privacy | Mobile
Web01 | 2.8.140721.1 | Last Updated 6 Jan 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100