Jump to content

[SOLVED] Problem with Contact Form


tmyonline

Recommended Posts

Guys: I built a simple contact form to receive users' comments.  It does not work.  Any ideas.  Below is the code.  I'll greatly appreciate any help.  Thanks.

 

<?php

  include('includes/corefuncs.php');    // nukeMagicQuotes();

 

  if (array_key_exists('send', $_POST)) {

 

            $to        = '[email protected]';

            $subject  = 'test';

 

// process the $_POST variables

$name      = $_POST['name'];

$email      = $_POST['email'];

$comment  = $_POST['comment'];

 

// build message

$message  = "Name: $name\n\n";

$message .= "Email: $email\n\n";

$message .= "Comment: $comment";

 

// send it

$mailSent = mail($to, $subject, $message);

  }

?>

<!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=utf-8" />

<title>Untitled Document</title>

</head>

 

<body>

<form id="form1" name="form1" method="post" action="">

  <label for="name">Name:</label>

  <input type="text" name="name" id="name" />

  <br />

  <br />

  <label for="email">Email:</label>

  <input type="text" name="email" id="email" />

  <br />

  <br />

  <label for="comments">Message:</label>

  <textarea name="comments" id="comments" cols="45" rows="5"></textarea>

  <br />

  <br />

  <input type="submit" name="send" id="send" value="Send message" />

</form>

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/63944-solved-problem-with-contact-form/
Share on other sites

I just followed my PHP book example.  I was surprised too.  What should "action" be then ?  Normally, "action" should take me to where I want the message to be processed.  In this case, everything is on the same page.  Is it the reason why the author left it blank ?  Hymn...

No, but that is a good question.

 

Say your PHP script is in the file "form.php".  You would enter the value "form.php" for the attribute action.

example:

<form id="form1" name="form1" method="post" action="form.php">

 

OR...

 

There is a PHP variable that echos the name of the file that it is being executed in.  So instead you could use:

<form id="form1" name="form1" method="post" action="<?php echo $PHP_SELF;?>">

This way, if you rename the file from form.php to anything else, it will always point back at itself.

 

Here is a great tutorial.  Check it out.  It also gives explanations.

http://www.tizag.com/phpT/examples/formex.php

a couple of things

 

1. lose the array_key_exists and use if (isset ($_POST['submit'])) {

2. lose the $mailSent = just use mail($to, $subject, $message);

3. you have $comment =$_POST['comment']; but your textarea id is comments

4. use action="<?php echo $_SERVER['PHP_SELF']; ?>" for your form

 

should work

 

 

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.