Help - Search - Members - Calendar
Full Version: Help! What's Missing Here?
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
ruifor2
hi, I gived up!!! prob it is very easy for u so I decided to ask for help.
this is my web page and bellow there is my php file.

why is not working????



<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Micro Contact Form</title>
<link href="style/style.css" rel="stylesheet"
type="text/css">
</head>
<body>
<div id="main">
<div id="caption">Contact us</div>
<div id="icon"> </div>
<?php
if (!isset($_POST['submitBtn'])) { createForm();
} else { $name = isset($_POST['name']) ? $_POST['name'] : "";
$email = isset($_POST['email']) ? $_POST['email'] : "";
$message = isset($_POST['message']) ? $_POST['message'] : "";
$error = false;
if (strlen($name)<2) {
$error = true;
$error1 = errorName;
}
if (!isValidEmail($email)) {
$error = true;
$error2 = errorEmail;
}
if (strlen($message)<10) {
$error = true;
$error3 = errorMsg;
}
if ($error){
createForm($name,$email,$message,$error1,$error2,$error3); }
else {
sendMail($name,$email,$message);
?>
<div id="result">
<table width="100%">
<tbody>
<tr>
<td>Thanks for your message!
</td>
</tr>
</tbody>
</table>
</div>
<?php }
}
?>
<div></div>
</div>
</body>
</html>



and the php file looks like these:


<?php


define("MAIL_TARGET","yourmail@mail.com");

// Here you can redefine error messages
define("errorName","Invalid name! It must be at least 2 characters long");
define("errorEmail","Invalid email address!");
define("errorMsg","Invalid message! It must be at least 10 characters long");

function createForm($name="",$email="",$message="",$error1="",$error2="",$error3=""){
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table>
<tr><td>Name: </td><td class="error"><?php echo $error1; ?></td></tr>
<tr><td colspan="2"><input class="text" type="text" name="name" value="<?php echo $name; ?>"></td></tr>
<tr><td>Email:</td><td class="error"><?php echo $error2; ?></td></tr>
<tr><td colspan="2"><input class="text" type="text" name="email" value="<?php echo $email; ?>"></td></tr>
<tr><td>Message:</td><td class="error"><?php echo $error3; ?></td></tr>
<tr><td colspan="2"><textarea cols="40" rows="6" name="message"><?php echo $message; ?></textarea></td></tr>
<tr><td colspan="2"><br/><input class="text" type="submit" name="submitBtn" value="Send"></td></tr>
</table>
</form>
<?php
}

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;
}
}

function sendMail($name,$email,$message){

$subject = "Message from website";
$from = "From: $name <$email>\r\nReply-To: $email\r\n";
$header = "MIME-Version: 1.0\r\n"."Content-type: text/html; charset=iso-8859-1\r\n";
$content = htmlspecialchars($message);

$content = wordwrap($content,70);
mail(MAIL_TARGET,$subject,$content,$from.$header);

}
?>
please explain all procedures because I'm a rookie in scripts
tanks
swordz
2 problems, 1 major and 1 minor/possibly me not knowing php.

1st. mail() is disabled. But you can have it enabled for $10, talk to Jack in the IRC.

2nd. createForm($name,$email,$message,$error1,$error2,$error3); $error1/2/3 have not necessarily been set.

swordz
ruifor2
QUOTE(swordz @ Oct 28 2008, 11:42 PM) *
2 problems, 1 major and 1 minor/possibly me not knowing php.

1st. mail() is disabled. But you can have it enabled for $10, talk to Jack in the IRC.

2nd. createForm($name,$email,$message,$error1,$error2,$error3); $error1/2/3 have not necessarily been set.

swordz



tanks swordz
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.