Web Hosting Talk







View Full Version : Contact Us Form


saqibisdon
07-19-2004, 11:41 AM
hi,

i was wondering if anyone could recommend a decent "contact us" form. I have searched hotscripts but a lot of them don't have demo's and i really want to see them before i install them.

anyway, im looking for a free script, with as many features as possible and one major requirement is that you can set up multiple contacts, as in theuser can select which department he wants to email to.

thanks for any help!

Saqib

Burhan
07-19-2004, 11:53 AM
Just create one yourself. I have created many of these, and they are very simple to do.

Corey Bryant
07-19-2004, 12:14 PM
Check with your hosting company. Most provide the source code that is compatible with their server to create a contact form.

SniperDevil
07-19-2004, 03:26 PM
It is extremely easy to create a PHP contact form simply using the mail function. Look up the mail function on php.net. That's all you need, and you need to collect Department info from the select menu on the contact page via Javascript, if you want mail to be sent to different addresses upon the user selecting a different department.

BitChucker
07-19-2004, 04:31 PM
I did this script many moons ago for my ex g/friend's site, it's a pretty standard one and could probably be cleaned up pretty significantly now I know what I'm doing but alas I cba. It's ugly but it works and has some basic error checking.

If you want to expand it just let me know and I'll help along as needed.

Crikey, I just hit submit and then I start seeing possible issues with it...editing as we speak :eek:

Here's the PHP, save it to a file called formmail.php

<?php
$name=$_POST['name'];
$email=$_POST['email'];
$feedback=$_POST['feedback'];

if ($name==false || $email==false || $feedback==false)
{
echo ("Please ensure that you filled out all fields in the form.<p>Use your browser's \"Back\" button to return to the previous page and try again.");
}

elseif (!eregi('^[a-zA-Z0-9_\-\.]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$', $email))
{
echo "I'm sorry but I don't recognise the supplied email address as being valid. Please return to the previous page and try again.";
}
else {
$feedback=stripslashes($feedback);
$toaddress = $_POST['to'];
$subject = 'Feedback from web site';
$mailcontent = 'Customer name: '.$name."\n\n"
.'Customer email: '.$email."\n\n"
."Customer comments: \n\n".$feedback."\n";
$fromaddress = 'From: '.$email;
$name=trim($name);
$email=trim($email);
mail ($toaddress, $subject, $mailcontent, $fromaddress);
echo "Thanks for emailing us! We hope you like the site.
}
?>

And now the HTML form (doesn't matter what you call this, just wrap it in some HTML and BODY tags):

<form name="form1" method="post" action="formmail.php">
<input name="page" type="hidden" id="page" value="Contact">
<p>Your name:<br>
<input name="name" type="text" id="name">
</p>
<p>Your email address:<br>
<input name="email" type="text" id="email">
</p>
<p>Going to:<br>
<select name="to" id="to">
<option value="you@yourserver.com">YOU</option>
<option value="him@himserver.com">HIM</option>
</select>
</p>
<p>Your comments:<br>
<textarea name="feedback" cols="40" rows="5" id="feedback"></textarea>

</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>

BitChucker
07-19-2004, 04:57 PM
It is of course essential to state at this point that I do not guarantee the security of this script!

Accepting user input is a risky business, they could type in all kinds of malicious code which COULD potentially exploit a computer or your server.

The formmail solution I posted above MUST be edited to implement some form of security against such exploits. The strip_tags() function in PHP is a good place to start.

xelav
07-21-2004, 01:54 PM
take as a base BitChucker's script and improve as you wish :)
As for me, I'll add cutting string to some length, and also IP sending.