Need a contact form

babuciu_andrei

Baseband Member
Messages
24
Hello,

I need a contact form on my website, that will send to my email address what the visitor enter in the form fields. The problem is that I can't run any php scripts.. is there a way to use some html form?
 
In order to process a form like that, you need some kind of server-side scripting. Html won't do it, btw, you should probably have posted this in the web programming section. Can you use cgi, coldfusion, or asp? Don't know if you can use javascript or not... Let me check on that.
 
<head>
<script type="text/javascript">
function emailMe() {
var mySubject = new String(document.form1.elements[0].value + "");
var myEmail = new String(document.form1.elements[1].value + "");
var messageText = new String(document.form1.elements[2].value + "");
window.location ="mailto:" + myEmail + "&subject=" + mySubject +"&body=" + messageText;
}
</script>
</head>
<body>
<form name="form1" id="form1" method="post" action="">
Subject: <input type="text" name="mySubject" id="mySubject" /><br />
Email: <input type="text" name="email" id="email" /><br />
Message:<br />
<input type="textarea" name="message" id="message" style="height: 100px; width: 150px;" /><br />
<INPUT TYPE="button" VALUE="Contact Us" onClick="emailMe();" />
</form>
</body>
Thats the closest you'll get (as far as I know) without any server side code. I wrote that, so you don't have to give credit, just hope it helps.

Also, this does not work on firefox. It throws an exception that I have no idea how to correct. So, stick with I.E. :(
 
A code that only works on IE is a bad code :p

You can set up a basic one by using HTML and PHP.

Add a PHP page with this code:
Code:
<form action="contact2.php" method="post">
Name:<input type="text" name="name" class="text" size="41"/><br />
Email:<input type="text" name="email" id="email" class="text" size="41"/><br />
Subject:<input type="text" name="subject" class="text" size="41"/><br />
Message:<textarea name="message" class="text" cols="38" rows="10"></textarea><br />
<input type="hidden" name="ip" value="<?php echo ($_SERVER['REMOTE_ADDR']); ?>"/>
<input type="submit" name="send" value="Send" class="button"/>
<input type="reset" name="clear" value="Clear" class="button"/>
</form>

Then make a new page called contact2.php and add this code:

PHP:
<?php

$name = htmlentities($_POST['name']);
$email = htmlentities($_POST['email']);
$subject = htmlentities($_POST['subject']);
$message = htmlentities($_POST['message']);
$ip = htmlentities($_POST['ip']);

    $mailto = "email@domain.com";
    $mailsubj = "$subject\n";
    $headers = "From: $email\r\n" . "IP: $ip\r\n";
    $mailbody = $message;
    mail($mailto, $mailsubj, $mailbody, $headers);
    echo '<div>Your message has been sent</div>';
?>

This script is for demo purposes though, edit them as you see fit. Also, it is wise to add extra coding on contact2.php to stop people from sending blank messages.

EDIT: For the script to work correctly, you need to have the mail(); command enabled on the webserver. Some hosts enable a safe mode which blocks it so you may need to ask them about it. There are ways around it however.

Jamie.
 
wow how do you learn to write code like that, and where do you input that code ?

*bewildered*
 
Oh, didn't notice the bit about PHP. My bad :p

But move to a host that supports PHP, you will need it for many scripts. A host that doesn't offer PHP and a database sucks to be honest :p
 
Back
Top Bottom