Tu je ten kod.Skusal som to a ide to len vo FF
Kód:
<?php
class maxContact {
var $subjectText = "Message via Max's Contact Form";
var $targetEmail = "demo@demo.com";
var $mailFormat = "text/plain";
var $fieldList;
var $errorList;
var $email = '';
var $name = '';
var $message = '';
var $additionalText = '';
function maxContact(){
//Extend the list as you want here
$this->fieldList[0]['caption'] = "City";
$this->fieldList[0]['fieldName'] = "city";
$this->fieldList[0]['value'] = "";
$this->fieldList[1]['caption'] = "State";
$this->fieldList[1]['fieldName'] = "state";
$this->fieldList[1]['value'] = "";
}
function showForm(){
$message = '';
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="post">';
echo ' <table>';
echo ' <tr><td>Name:</td></tr>'
.' <tr><td><input type="text" name="name" value="'.$this->name.'" /></td></tr>';
echo ' <tr><td>Email:</td></tr>'
.' <tr><td><input type="text" name="email" value="'.$this->email.'"/></td></tr>';
// Now display additional elements
foreach ($this->fieldList as $value) {
echo ' <tr><td>'.$value['caption'].':</td></tr>'
.' <tr><td><input type="text" name="'.$value['fieldName'].'" value="'.$value['value'].'" /></td></tr>';
}
echo ' <tr><td>Message:</td></tr>'
.' <tr><td ><textarea cols="40" rows="6" name="message">'.$this->message.'</textarea></td></tr>'
.'<tr><td><input type="image" src="style/images/btn_submit.gif" name="submitBtn" value="Send" /></td></tr>';
echo ' </table>';
echo '</form>';
}
function sendMail() {
$subject = $this->subjectText;
$from = "From: $this->name <$this->email>\r\nReply-To: $this->email\r\n";
$header = "MIME-Version: 1.0\r\n"."Content-type: $this->mailFormat; charset=iso-8859-1\r\n";
$content = $this->message;
if ($this->additionalText != ''){
$content .= "\r\n\r\nAdditional information:\r\n\r\n"
.$this->additionalText;
}
$content = wordwrap($content,70);
@mail($this->targetEmail,$subject,$content,$from.$header);
}
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 processForm(){
if (isset($_POST['submitBtn'])){
$email = isset($_POST['email']) ? trim($_POST['email']) : '';
$name = isset($_POST['name']) ? trim($_POST['name']) : '';
$message = isset($_POST['message']) ? trim($_POST['message']) : '';
if (!$this->isValidEmail($email)) $this->errorList[] = "Invalid email address!";
if (strlen($name)<2) $this->errorList[] = "Invalid name! It must be at least 2 characters long.";
if (strlen($message)<5) $this->errorList[] = "Invalid message! It must be at least 10 characters long.";
$this->email = $email;
$this->name = $name;
$this->message = htmlspecialchars($message);
foreach ($this->fieldList as $key=>$value) {
if (isset($_POST[$value['fieldName']])) {
$this->fieldList[$key]['value'] = $_POST[$value['fieldName']];
$this->additionalText .= $value['caption'] . " : " . $_POST[$value['fieldName']]."\r\n";
}
}
if (sizeof($this->errorList) > 0){
$this->showErrors();
$this->showForm();
} else {
$this->sendMail();
$this->showInfo();
}
} else {
$this->showForm();
}
}
function showErrors(){
echo '<ul class="error">';
foreach ($this->errorList as $value) {
echo " <li>$value</li>";
}
echo "</ul>";
}
function showInfo(){
echo "<p>Thanks for your message!</p>";
}
}
?>
Ak by si to chcel vyskusat tak tu je index
Kód:
<?php require_once("maxContact.class.php"); ?>
<!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>Max's Contact Form</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="container">
<div id="header"><div id="header_left"></div>
<div id="header_main">Max's Contact Form</div><div id="header_right"></div></div>
<div id="content">
<?php
$myContact = new maxContact();
$myContact->processForm();
?>
</div>
<div id="footer"><a href="http://www.phpf1.com" target="_blank">Powered by PHP F1</a></div>
</div>
</body>