Jump to content

Recommended Posts

Gday, im trying to code a contact form for my website. When I run this code, it doesnt seem to get information from my form. For example it doenst print out the name out in the confirmation page. Help?

 

Any help would be fantastic :)

contact.html

<!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>Contact Us</title>
</head>
<body>

<form action="contactForm.php" method=”post”>

Name:
<br />
<input type=”text” name=”name” />

<br /><br />

Email Address:
<br />
<input type=”text” name=”email” />

<br /><br />

Comments:
<br />
<textarea rows=”10? cols=”20? name=”comments”> </textarea>

<br /><br />
<input type="submit" value="send" />

</form>

</body>
</html>

 

contactForm.php

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];

$to = “[email protected]“;
$subject = “Comments From Website”;

$input_name = “Name: $name\n\n”;
$input_email = “Email: $email\n\n”;
$input_comments = $comments;

$message = $input_name.$input_email.$input_comments;

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=iso-8859-1? />
<title>Comments received</title>
</head>
<body>

<h2>Your comments are appreciated.</h2>

<p><strong><?php echo($name); ?></strong>, we value your comments.
We will see that we promptly reply to you at the following email address: <?php echo($email); ?></p>
</body>

</html>

 

 

Link to comment
https://forums.phpfreaks.com/topic/205392-php-basic/
Share on other sites

Most of the quotes in your HTML markup are smart-quotes/curly-quotes (i.e. ” and “)

 

Your HTML markup should only contain straight quotes " or '

 

yeah i noticed that as well before you posted. And i changed them all, but now it information wont even post (the data wont show up in the addresss bar when i click submit). So now i'm back to square 1.

 

Edit: Here is the code with all the quotes fixed

 

<?xml version="1.0" encoding="iso-8859-1"?>
<!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>
<title>Contact Us</title>
</head>
<body>

<form action="contactForm.php" method="post">

Name:
<br />
<input type="text" name="name" />

<br /><br />

Email Address:
<br />
<input type="text" name="email" />

<br /><br />

Comments:
<br />
<textarea rows="10" cols="20" name="comments"> </textarea>

<br /><br />
<input type="submit" value="send" />

</form>

</body>
</html>

 

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$comments = $_POST['comments'];

$to = "[email protected]";
$subject = "Comments From Website";

$input_name = "Name: $name\n\n";
$input_email = "Email: $email\n\n";
$input_comments = $comments;

$message = $input_name.$input_email.$input_comments;

mail($to,$subject,$message);
?>
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd”>
<?xml version="1.0" encoding="iso-8859-1"?>
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>

<title>Comments received</title>
</head>
<body>

<h2>Your comments are appreciated.</h2>

<p><strong><?php echo($name); ?></strong>, we value your comments.
We will see that we promptly reply to you at the following email address: <?php echo($email); ?></p>
</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/205392-php-basic/#findComment-1074873
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.