<?php
require_once('phpmailer/class.phpmailer.php');
require_once('xajax/xajax.inc.php');
$form = '<form id="cform">
<div>
<label for="name">Name</label>
<input name="name" type="text" id="naam" value="" size="25" />
</div>
<div>
<label for="email">E-mail</label>
<input name="email" type="text" id="email" value="" size="25" />
</div>
<div>
<label for="msg">Message</label>
<textarea name="msg" id="msg" cols="45" rows="5"></textarea>
</div>
<div style="border-top:1px solid #CCCCCC;padding-top:5px;">
<label for="subbtn" style="text-align:right;"> --> </label>
<input type="button" id="subbtn" value="Submit" onclick="xajax_myFunction(xajax.getFormValues(\'cform\'));" />
</div>
</form>';
function myFunction($get) {
global $form, $error;
$error = '';
$objResponse = new xajaxResponse();
$show_form = true;
if (!empty($get['email']) && !empty($get['msg']) && !empty($get['name'])) {
if (preg_match("/^[\w-]+(\.[\w-]+)*@([0-9a-z][0-9a-z-]*[0-9a-z]\.)+([a-z]{2,4})$/i", trim($get['email']))) {
$email = preg_replace("/\r\n/", "", $get['email']);
$from = preg_replace("/\r\n/", "", $get['name']);
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.yourserver.com";
$mail->SMTPAuth = true;
$mail->Username = "postmaster@yourserver.com";
$mail->Password = "password";
$mail->From = "postmaster@yourserver.com";
$mail->FromName = "Webmaster";
$mail->AddAddress("admin@yourserver.com");
$mail->AddReplyTo($email, $from);
$mail->Subject = "contact form using Xajax and phpmailer";
$mail->Body = $get['msg'];
if ($mail->Send()) {
$error = "The form is submitted and the mail is send.";
$show_form = false;
} else {
$error = "There was a problem while sending the mail, please try again";
}
} else {
$error = "The entered e-mail address is not valid.";
}
} else {
$error = "At least one of the fields is empty...";
}
$data = (!$show_form) ? '<p class="contactMsg">'.$error.'</p>' : '<p class="contactMsg">'.$error.'</p>'.$form;
$objResponse->addAssign('contact_result', 'innerHTML', $data);
return $objResponse;
}
$xajax = new xajax();
$xajax->registerFunction('myFunction');
$xajax->processRequests();
?>
<html>
<head>
<title>Form</title>
<?php $xajax->printJavascript('xajax/'); ?>
</head>
<body>
<div class="content1-container-1col">
[INDENT]<div class="content-txtbox-noshade">
<p>
Please use the form below to get in touch with me. Please use a suitable subject to describe what you're writing about.
</p>
<?php echo '<div id="contact_result">'.$form.'</div>'; ?>
</div>[/INDENT]
</div>
</body>
</html>