Jump to content

contact form messages in new page, HOW.


moise

Recommended Posts

hello i am trying to build a contact form but i am having the following problem and wonder if anyone could help. i need to the contact form to able to show success or error message in a new page and verify if all fields have been filled, how do i do that please?

[code]<?php
if(isset($_POST['submit'])) {

  $to = "user1@yahoo.com, user2@yahoo.com";
 
 
  $name_field = $_POST['name'];
  $email_field = $_POST['email'];
  $subject = $_POST['subject'];
  $message = $_POST['message'];
  $body = "$message";

  $continue = "/"; // will send me to my  homepage

[b]echo "Thanks $name_field, Your message has been submitted to $to!";
<p><a href="<?php print $continue; ?>">Click here to continue</a></p>"[/b]
// i need to display the lines above in a new page
mail($to, $subject, $body);

} else {

echo "OH NOOOO!";

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>


</body>
</html>
[/code]

i am getting the following error: [quote]Parse error: syntax error, unexpected $end in /home/.malcsi/moisea66/tyreese.upfrontec.com/mailer.php on line 39[/quote]

many thanks.
Link to comment
Share on other sites

You went from PHP to HTML without closing your PHP. Try this.
[code]
$continue = "/"; // will send me to my  homepage
echo "Thanks $name_field, Your message has been submitted to $to!";
?><p><a href="<?php print $continue; ?>">Click here to continue</a></p><?
mail($to, $subject, $body);[/code]
Link to comment
Share on other sites

thanks jesirose it works, but how will i make the messages display on a new page message.php for exple. i also notice this form sends emails without any field being filled how would i make a stop on it. sorry might be dumb questions but i am new.
i started a server sidec email verification function[code]// Function  email address validation checking
  function isValidEmail($email){
      $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
   
      if (eregi($pattern, $email)){
        return true;
      }
      else {
        return false;
      } 
  }[/code]
but it seems that does not stop it from sending bank email .
many thanks.
Link to comment
Share on other sites

i sorted [quote]how will i make the messages display on a new page message.php for exple.[/quote] but still have a problem of verification of fields. this is what i've got for the email verificaton, but doen't seem right because it keep telling me that my email address is invalid.here's the code
[code]<?php
// Function  email address validation checking
  function isValidEmail($email){
      $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
   
      if (eregi($pattern, $email)){
        return true;
      }
      else {
        return false;
      } 
  }


        if (isset($_POST['submit']))
        {
            if (isValidEmail($_POST['email'])){
                echo "The email: ".$_POST['email']." is valid! ";
            }
            else{
                echo " The email: ".$_POST['email']." is invalid! ";
            }
        }
      ?>[/code]
any idea how to verify an text field too?
many thanks.
Link to comment
Share on other sites

thanks matt, this is what i came up with:
[code]<?php
if(isset($_POST['submit'])) {

  $to = "moisea@yahoo.com, moise_tavares@yahoo.com";
 
  $subject = $_POST['subject'];
  $name_field = $_POST['name'];
  $email_field = $_POST['email'];
  $message = $_POST['message'];
  $body = "$message";
  $continue = "/"; // homepage or "mypage.htm" or "http://www.elsewhere.com/page.htm"

  // email validation
  $error_msg='';

          if(trim($name)==''{
              $error_msg.="Please enter your Name and/or Surname !<br>";
    }

          if(trim($subject)=='' {
              $error_msg.="Please enter a subject title !<br>";
    }

if(trim($email_input)=='') {
          $error_msg.="Please enter an email<br>";
    } else {
          // check if email is a valid address in this format username@domain.com
          if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email_input)) $error_msg.="Please enter a valid email address<br>";
    }
     
      // display error message if any, if not, proceed to other processing
      if($error_msg==''){
          // other process here
      } else {
          echo "<font color=red>$error_msg</font>";
      }
}

mail($to, $subject, $body);

} else {

echo "OH NOOOO!";

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<div id="contact-message">

<!--Thank you <b><?php $name_field ?></b>
<br>Your message has been sent to <b><?php $to ?></b>
<p><a href="<?php print $continue; ?>">Click here to continue</a></p> -->
<?php
echo "Thanks <b>$name_field</b>, Your message has been submitted to <b>$to</b>!";
?><p><a href="<?php print $continue; ?>">Click here to continue</a></p>

</div>
</body>
</html>
[/code]
but i am getting this parse error:[quote]Parse error: syntax error, unexpected '{' in /home/.malcsi/myusername/myweb.com/mailer.php on line 16[/quote]
when i deleted the "{" i get the following parse too.[quote]Parse error: syntax error, unexpected T_VARIABLE in /home/.malcsi/myusername/myweb.com/mailer.php on line 17[/quote]
can someone help me fix this problem please?
many thanks.
Link to comment
Share on other sites

[code]<?php
if(isset($_POST['submit'])) {

  $to = "moisea@yahoo.com, moise_tavares@yahoo.com";
 
  $subject = $_POST['subject'];
  $name_field = $_POST['name'];
  $email_field = $_POST['email'];
  $message = $_POST['message'];
  $body = "$message";
  $continue = "/"; // homepage or "mypage.htm" or "http://www.elsewhere.com/page.htm"

  // email validation
  $error_msg='';

  if(trim($name)=='') {
$error_msg.="Please enter your Name and/or Surname !<br>";
  }

  if(trim($subject)=='') {
    $error_msg.="Please enter a subject title !<br>";
  }

if(trim($email_input)=='') {
    $error_msg.="Please enter an email<br>";
  } else {
    // check if email is a valid address in this format username@domain.com
    if(!ereg("[0-9a-z]([-_.]?[0-9a-z])*@[0-9a-z]([-.]?[0-9a-z])*\\.[a-z]", $email_input)) {
    $error_msg.="Please enter a valid email address<br>";
    }
     
    // display error message if any, if not, proceed to other processing
    if($error_msg==''){
      // other process here
    } else {
      echo "<font color=red>$error_msg</font>";
    }
  }

  mail($to, $subject, $body);

} else {
  echo "OH NOOOO!";
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>

<div id="contact-message">

<!--Thank you <b><?php $name_field ?></b>
<br>Your message has been sent to <b><?php $to ?></b>
<p><a href="<?php print $continue; ?>">Click here to continue</a></p> -->
<?php
echo "Thanks <b>$name_field</b>, Your message has been submitted to <b>$to</b>!";
?>
<p><a href="<?php print $continue; ?>">Click here to continue</a></p>

</div>
</body>
</html>[/code]

You were missing 2 sets of ) (one was mentioned above) and you had a missing { on an if statement
Link to comment
Share on other sites

thanks kingphilip, i did the changes before... the error was in here in fact.
[code]} else {
  echo "OH NOOOO!";
} [/code] i had to just delete it.
but the bad new is it sends email, but i get the mailer.php page the following wierd message
[quote]
Please enter your Name and/or Surname !
Please enter a subject title !
Please enter an email
Thanks , Your message has been submitted !

Click here to continue
[/quote]
this happened, when i tried to both send a empty form and a form with just the email field filled, meaning doesn't check my form fields for validation. how did i managed that ??? ? ??? ?
These are the php details of my form.
[code]
form action="mailer.php" method="post">
<input type="text" name="name" value="<? echo $name; ?>" size="30" />
<input  type="text" name="email" value="<? echo $email; ?>" size="30" />
<input  type="text" name="subject" value="<? echo $subject; ?>" size="30" />
<textarea  name="message" cols="25" rows="4"></textarea>
<input type="submit" value="Send" name="submit" class="button" />
<input type="reset" value="Reset" class="button" />
[/code]
many thanks again.
Link to comment
Share on other sites

hi, nearly there! :)
the only error i am getting is, it does recognise my email. i am not getting the "please enter an email address" but i am getting "Please enter a valid email address" any ideas on how to solve this current problem please?
i checked the mail validation and it seems correct to me.
many thanks.
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.