how do i make a contact form

coolv1994

Member
Messages
508
Reaction score
0
Points
16
ive tried diffrent codes but none of them workso will someone give me a working code for a contact form
 

Chris73

New Member
Messages
5,356
Reaction score
1
Points
0
You need to make 2 files. One for the "PHP" and one for the "Java Script"

Code:
<?php
/*




This script is a basic contact form which uses AJAX to pass the information to php, thus making the page appear to work without any refreshing or page loading time.

*/

$to = "[B]EMAIL HERE[/B]"; //This is the email address you want to send the email to
$subject_prefix = "[B]User Name here[/B]"; //Use this if you want to have a prefix before the subject

if(!isset($_GET['action']))
{
die("You must not access this page directly!"); //Just to stop people from visiting contact.php normally
}

/* Now lets trim up the input before sending it */

$name = trim($_GET['name']); //The senders name
$email = trim($_GET['email']); //The senders email address
$subject = trim($_GET['subject']); //The senders subject
$message = trim($_GET['msg']); //The senders message

mail($to,$subject,$message,"From: ".$email.""); //a very simple send

echo 'contactarea|Thank you '.$name.', your email has been sent.'; //now lets update the "contactarea" div on the contact.html page. The contactarea| tell's the javascript which div to update.
?>

The java script portion
Code:
function createRequestObject() {
    var ro;
    var browser = navigator.appName;
    if(browser == "Microsoft Internet Explorer"){
        ro = new ActiveXObject("Microsoft.XMLHTTP");
    }else{
        ro = new XMLHttpRequest();
    }
    return ro;
}

var http = createRequestObject();

function sendemail() {
	var msg = document.contactform.msg.value;
	var name = document.contactform.name.value;
	var email = document.contactform.email.value;
	var subject = document.contactform.subject.value;
	document.contactform.send.disabled=true; 
	document.contactform.send.value='Sending....';

    http.open('get', 'contact/contact.php?msg='+msg+'&name='+name+'&subject='+subject+'&email='+email+'&action=send');
    http.onreadystatechange = handleResponse;
    http.send(null);
}

function handleResponse() {
    if(http.readyState == 4){
        var response = http.responseText;
        var update = new Array();

        if(response.indexOf('|' != -1)) {
            update = response.split('|');
            document.getElementById(update[0]).innerHTML = update[1];
         
        }
    }
}
 
Last edited:

adrenlinerush

New Member
Messages
379
Reaction score
1
Points
0
write your own... you can make the form in html and write a cgi script to recieve the post... you can do it in perl, php, python, ruby and several others... and its not difficult... i'm sure if you google you can find plenty pre-made...
 
Top