simple feedback form


#1
<?php
if (array_key_exists('send', $_POST)) {
	$to = 'karl_uoi@hotmail.com';
	$subject = 'contact form super saver';

	$name = $_POST['name'];
	$email = $_POST['email'];
	$Tel = $_POST['Tel'];
	$message = $_POST['message'];

	$message = "Name: $name\n\n";
	$message .= "email: $email\n\n";
	$message .= "Tel: $Tel\n\n";
	$message .= "message: $message";

	$message = wordwrap($message, 70);
	$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">

<style type="text/css" media="screen">

body {

	background-color:#FFF;

	color:#252525;

	font-family:Arial, Helvetica, sans-serif;

	font-size:100%;

}

h1{

	font-family:Verdana, Geneva, sans-serif;

	font-size:150%;

}

p{

	font-size:85%;

	margin:0 0 5px 25px;

	max-width: 650px;

}

form {

	width:600px;

	margin:15px auto 10px 20px;

}

label {

	display:block;

	font-weight:bold;

}

textarea {

	width:400px;

	height:150px;

}

.textinput {

	width:250px;

}



fieldset {

	border:#000 1px solid;

	margin-top:40px;

}

.warning {

	font-weight:bold;

	color:#ff0000;

}

</style>


<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>Untitled Document</title>

</head>



<body>

<h2>Contact Us </h2>



<?php
if ($_POST && !$mailSent) {
?>
<p class="warning">Sorry something went wrong when sending your message. Please try again. If your problem persists please contact your system admin or try again later. </p>
<?php
}
elseif ($_POST && $mailSent) {
?>
<p><strong>Your message has been sent. We will do everything we can to reply as fast as possible</strong></p>
<?php } ?>
<p>Please fill in your required message below and fill out all fields. We will aim to reply to your message as fast as possible.</p>

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

  <fieldset>

    <legend>Your Details</legend>

    <p>

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

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

    </p>

    <p>

      <label for="email">E mail:</label>

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

    </p>

    <p>

      <label for="Tel">Tel.</label>

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

    </p>

  </fieldset>

  <fieldset>

    <legend>Your Message</legend>

    <p>

      <label for="message">Your Message:</label>

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

    </p>

    <p>

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

    </p>

  </fieldset>

</form>

<p>&nbsp;</p>

</body>

</html>

i am new this and this is my first php script. I plut to together the simple script that i wast to send the form information to my email address. all as i can seem toget when submit is clicked is the error message i implememnted below.

[php]

<?php if ($_POST && !$mailSent) { ?>

Sorry something went wrong when sending your message. Please try again. If your problem persists please contact your system admin or try again later.

[/php]

i am sure that this is something very simple but im very new to this and cant see it. Any light shed on this would greatly be appreciated.

regards,

karl


#2
hello karlc87, your code looking fine but i think below modification may be helpful for you. replace below code if (array_key_exists('send', $_POST)) { with below code if ($REQUEST_METHOD == 'POST') {

i this will help you and point in right direction
SR


#3

I am not sure on your testing for mail sending!
First, sending the mail does NOT post the page. So the line:
if ($_POST && !$mailSent) {
Does nothing as sending the mail does not post.

Just use if (!$mailSent) {

The value returned using the mail function ( mailsent=mail() ) is ‘true’ if the mail was sent, ‘false’ if it fails to send. So, using just if(mailSent) is all you need. It is not a posted variable. Hope that helps…


#4

thanks for the replies, i’ve actually just found the problem

i had put

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

when it should have been

[code][code]

send was capitilized, when it shouldn’t have been. As quick as i solve one problem i encounter another. I can now send the form but in the email account i recieve 2 of every bit of data (name, email, tel) but dont recieve the the message.

reagards

karl[/code]


#5

maybe i was a little hasty sending the second fault. Again i sorted the problem. I apologise for the repeat post couldnt find where to edit the last message. It wasn’t sending the correct information because i had doubled up the $message so i was confusing it, or me to be more precise.

[php]

<?php if (array_key_exists('send', $_POST)) { $to = 'karl_uoi@hotmail.com'; $subject = 'contact form super saver'; $name = $_POST['name']; $email = $_POST['email']; $Tel = $_POST['Tel']; $message = $_POST['message']; $message = "Name: $name\n\n"; $message .= "email: $email\n\n"; $message .= "Tel: $Tel\n\n"; $message .= "message: $message"; $message = wordwrap($message, 70); $mailSent = mail($to, $subject, $message); } ?>

[/php]

i changed it to

[php]

<?php if (array_key_exists('send', $_POST)) { $to = 'karl_uoi@hotmail.com'; $subject = 'contact form super saver'; $name = $_POST['name']; $email = $_POST['email']; $Tel = $_POST['Tel']; $comments = $_POST['comments']; $message = "Name: $name\n\n"; $message .= "email: $email\n\n"; $message .= "Tel: $Tel\n\n"; $message .= "Message: $comments"; $message = wordwrap($message, 70); $mailSent = mail($to, $subject, $message); } ?>

[/php]

i changed the form label too comments aswell as edit the php code were needed.

just thought i would post what i found might be useful to somebody if they encounter the same problem, possibly someone out there as stupid as me.

im going to attempt to add some more arrays in for security, cant see that going wel first time so im sure i willl be back shortly. Thanks for the help.

regards

karl


#6

Thanks for the fixed posting. It is always helpful to others!

PS: You can not edit your own posts as a “New Member”. You will be able to in the future, if you continue to be a member of the site. This is a security option to keep out spammers. Thanks again for posting the corrected code…