User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 423,610 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,189 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 766 | Replies: 2 | Solved
Reply
Join Date: Dec 2006
Location: Texas
Posts: 29
Reputation: jonathan.jbkt is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jonathan.jbkt jonathan.jbkt is offline Offline
Unverified User

PHP Contact Form Help

  #1  
Sep 17th, 2007
I have a php email form that is giving me greif. It is sending blank messages. Could anyone take a look at the code and help. It would be greatly appreciated.

contact.php

<script LANGUAGE="JavaScript">
function Validate(form)
{
if (form.name.value == "")
{ alert("Please insert your name"); form.name.focus(); return; }
if (form.email.value == "")
{ alert("Please insert your E-mail"); form.email.focus(); return; }
if (form.comment.value == "")
{ alert("Please insert your comments or questions"); form.comment.focus(); return; }
if (form.email.value.indexOf('@', 0) == -1 || form.email.value.indexOf('.', 0) == -1)
{ alert("Your email is not valid."); form.email.focus(); return; }
form.submit();
}
</script>
                <img src="../images/head_contact.gif" width="230" height="36">
                  <table width="466" cellpadding="0" cellspacing="5">
            <form name="form1" method="post" action="sendmail.php">
                      <input name="subject" type="hidden" value="Contact Page Comment">
                      <tr> 
                        <td height="25" colspan="2">Name:&nbsp;&nbsp;</td>
                        <td height="25" colspan="2"> <input name="name" type="text" class="TEXT" size="40"> 
                        </td>
                      </tr>
                      <tr> 
                        <td height="25" colspan="2">Email:&nbsp;&nbsp;</td>
                        <td height="25" colspan="2"> <input name="email" type="text" class="TEXT" size="50"></td>
                      </tr>
                      <tr> 
                        <td height="40" colspan="2" valign="top">Comments or Questions:&nbsp;&nbsp;</td>
                        <td colspan="2"><textarea name="comment" cols="60" rows="5" class="TEXT"></textarea></td>
                      </tr>
                      <tr> 
                        <td>&nbsp;</td>
                        <td height="30" colspan="3" align="center" valign="bottom"> 
                          <input type="button" name="Button" value="Submit Comment" class="BUTTON" onClick="Validate(this.form)">
                          </td>
                      </tr>
                    </form>
                  </table>

sendmail.php

   <img src="../images/head_contact.gif" width="230" height="36">
                  <table width="466" cellpadding="0" cellspacing="5">
                      <tr>
                      <td>
                    <?PHP
                        //to address
                        $email_to = "jonathan@jbknowledge.com";
                        //from address
                        $headers = 'From: '.$email."\r\n"; 
                        //Send mail
                        mail($email_to,$subject,$comment,$headers);

                    ?>
                        Thank you for submitting your question! - Click <a href="http://www.askpriscilla.com"> here </a> to go back to the site.                         </td>
                    </tr>
                  </table>
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Apr 2005
Location: New York state
Posts: 465
Reputation: ShawnCplus will become famous soon enough ShawnCplus will become famous soon enough 
Rep Power: 5
Solved Threads: 72
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: PHP Contact Form Help

  #2  
Sep 17th, 2007
It's sending empty messages because $comment doesn't exist. You can get it by replacing $comment with $_POST['comment'].

Also, you $email in sendmail.php should be replaced with $_POST['email']
the same for $subject, it should be changed to $_POST['subject']
Last edited by ShawnCplus : Sep 17th, 2007 at 6:25 pm.
GCS d- s+:+ a-->? C++(++++) UL+++ P+>+++ L+++ !E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r z+*
Reply With Quote  
Join Date: Dec 2006
Location: Texas
Posts: 29
Reputation: jonathan.jbkt is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
jonathan.jbkt jonathan.jbkt is offline Offline
Unverified User

Re: PHP Contact Form Help

  #3  
Sep 17th, 2007
Originally Posted by ShawnCplus View Post
It's sending empty messages because $comment doesn't exist. You can get it by replacing $comment with $_POST['comment'].

Also, you $email in sendmail.php should be replaced with $_POST['email']
the same for $subject, it should be changed to $_POST['subject']


That got it working! Thank you very much. It is always fun trying to fix someone elses code...

Jonathan
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 8:49 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC