PHP Contact Us Form

Messages
740
Reaction score
1
Points
18
Hey,

I'm just looking for a little help from a tutorial putting everything together as one.

Tutorial: http://www.finalwebsites.com/tutorials/php_ajax_contact_form.php

Code for my site:

Code:
<div class="content1-container-1col">
<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>
 
</div>
</div>

Not quite sure what goes where with regards to the tutorial, anyone shed some light for me please?

Thanks in advance.
 

freecrm

New Member
Messages
629
Reaction score
0
Points
0
This is what I think it means...

but you would need to find the code for the required files (which isn't obvious)

PHP:
<?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;"> --&gt; </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>
 
Top