Click here to Skip to main content
15,892,927 members
Please Sign up or sign in to vote.
4.00/5 (1 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
XML
<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

XML
<?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
CSS
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
Comments
Sergey Alexandrovich Kryukov 3-Jan-13 15:06pm    
Actually, not "PHP form", "HTML form". One your problem is there.
—SA
Anselmo santos 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>

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
 
Share this answer
 
v2
Comments
Anselmo santos 3-Jan-13 15:12pm    
I did add the name="message" but i still have the same issue
Sergey Alexandrovich Kryukov 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 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 4-Jan-13 8:57am    
I cannot see what else is wrong with unarmed eye. You may need some debugging...
—SA
Anselmo santos 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>
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
 
Share this answer
 
You need to change

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 :)
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900