Jump to content

Email form help


Kitty

Recommended Posts

I have this email form, but everytime I try to send an email, it says[i] Please, go back and fill in a message![/i] even if I enter my message. Also, if I don't enter an email it sets it to anonymous, but I want it to be required and check if the email is valid. Here's the code:

[code]
<?php
//Change these variables to your needs
$yourmail = "mail@mail.com";

if(isset($_POST['mail'])) {
  //Do this IF post is TRUE
  echo("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>");
  if ($message!="") {
    //Do this IF message is TRUE
    if ($name!="") {
      //Do this IF name is TRUE
      if ($subject!="") {
        //Do this IF subject is TRUE


      if ($email!="") { } else { $email="Anonymous"; }//IF there is no email set by sender, SET it to Anonymous

        $message=htmlspecialchars($message); //htmlspecialchars makes sure " will show as " , instead of \"
        $name=htmlspecialchars($name); //Lets convert our name to htmlspecialchars as well
        $subject=htmlspecialchars($subject);
        $ip=GetHostByName($REMOTE_ADDR);


        $emailmessage= "
Mail generated by: PHP Mail Script\n
Script coded by: Arjan Peters\n
---------------------------------------------------------\n
Name: $name\n
E-Mail: $email\n
IP: $ip\n
---------------------------------------------------------\n
$message
"; //This is the layout for the e-mail message, \n indicates a New Line
          mail($yourmail, $subject, $emailmessage); //Send the mail PHP Function > mail(yourmail, subject, message)
          echo("<font size=\"2\" face=\"Verdana\">Thanks, $name. Your email has been sent.</font></td></tr></table>");

    } else {
        //Do this IF subject is FALSE
        echo("<font size=\"2\" face=\"Verdana\">Please, go <a href=\"javascript:history.back();\">back</a> and fill in a subject!</font></td></tr></table>");
      }
    } else {
      //Do this IF name is FALSE
      echo("<font size=\"2\" face=\"Verdana\">Please, go <a href=\"javascript:history.back();\">back</a> and fill in your name!</font></td></tr></table>");
    }
  } else {
    //Do this IF message is FALSE
    echo("<font size=\"2\" face=\"Verdana\">Please, go <a href=\"javascript:history.back();\">back</a> and fill in a message!</font></td></tr></table>");
  }


} else {
  //Do this IF post is FALSE
  ?>

<table border="0" cellpadding="0" cellspacing="0">
      <form method="post">
      <tr>
          <td>
              <font size="2" face="Verdana"><b>Name<font color="#FF0000">*</font>:</b></font>
              </td>
          <td>
              <input type="text" name="name" value="" size="25" maxlength="40">
              </td>
      </tr>
      <tr>
          <td>
              <font size="2" face="Verdana"><b>E-Mail:</b></font>
              </td>
          <td>
              <input type="text" name="email" value="" size="25" maxlength="50">
              </td>
      </tr>
      <tr>
          <td>
              <font size="2" face="Verdana"><b>Subject:</b></font>
              </td>
          <td>
        <select name="subject">
        <option value="QuestionComment">Question/Comment</option>
        <option value="Affiliation">Affiliation</option>
        <option value="LinkExchange">Link Exchange</option>
        <option value="GraphicRequest">Graphic Request</option>
        <option value="Bug">Bug Report</option>
        </select>
              </td>
      </tr>
      <tr>
          <td colspan="2">
              <font size="2" face="Verdana"><b>Message<font color="#FF0000">*</font>:</b></font>
              </td>
      </tr>
      <tr>
            <td colspan="2">
                <textarea rows="5" cols="35" name="message" maxlength="300"></textarea>
                </td>
      </tr>
      <tr>
          <td colspan="2">
              <input type="reset" value="Reset">
              <input type="submit" name="mail" value="Send">
              </td>
      </tr>
      <tr>
          <td colspan="2" align="center">
              <font size="2" face="Verdana"><font color="#FF0000">*</font> Required </font>
              </td>
      </tr>
</table>

<?php
}
?>[/code]

Please, help!
Link to comment
Share on other sites

These ones?

[code=php:0]if(isset($_POST['mail'])) {
  //Do this IF post is TRUE
  echo("<table border=\"0\" cellpadding=\"0\" cellspacing=\"0\"><tr><td>");
  if ($message!="") {
    //Do this IF message is TRUE
    if ($name!="") {
      //Do this IF name is TRUE
      if ($subject!="") {
        //Do this IF subject is TRUE


      if ($email!="") { } else { $email="Anonymous"; }//IF there is no email set by sender, SET it to Anonymous[/code]


Sorry, I'm not good at php!
Link to comment
Share on other sites

modify all occurances of this kind:[color=blue] if ($message!="")[/color]
to: [color=blue]if ($_POST['message']!="")[/color]

This is because if register_globals is set to Off at your host (as they should be), variables won't be detected unless you declare them first.
In this case you need to tell your script to look for $_POST['fieldname'] from your form.

So in order to use them, $var = $_POST['var'];
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.