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>

Recommended Answers

All 2 Replies

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']

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.