TP-Docs
HTML5 Icon HTML5 Icon HTML5 Icon
TP on Social Media

Recent

Welcome to TinyPortal. Please login or sign up.

May 04, 2024, 07:03:23 PM

Login with username, password and session length
Members
  • Total Members: 3,885
  • Latest: Growner
Stats
  • Total Posts: 195,178
  • Total Topics: 21,220
  • Online today: 81
  • Online ever: 3,540 (September 03, 2022, 01:38:54 AM)
Users Online
  • Users: 0
  • Guests: 54
  • Total: 54

A simple form for email response

Started by JPDeni, January 25, 2007, 05:43:00 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

JPDeni

Since there was a question about having a form to send information to the admin, I thought I'd make one that is more general that anyone can use.

This is very simple. It only includes text fields, and there is no error checking. I strongly suggest that, if you use this, you make it visible only to registered users. Otherwise spammers will use it.

Put the following into a php block:


$youremail = 'you@yourdomain.com'; // Enter your email address here
$emailtitle = 'Whatever you want your email title to be';

// List your fields here, like
//
// 'fieldname' => 'Field Name Label:',
//
// Don't put punctuation or spaces in fieldnames.

$fields = array (
  'field1' => 'Field One:',
  'field2' => 'Field Two:'
);

$endmessage = 'Thank you';

/////////////////////////////////////////////////////////////////////////////
// You do not need to edit anything below this line
/////////////////////////////////////////////////////////////////////////////
  $str = getenv("QUERY_STRING");
  if ($str)
    $action = 'index.php?'.$str;
  else
    $action = 'index.php';

if (isset($_POST['submit']))
{
  $text='';
  foreach ($fields as $field => $label)
  {
    isset($_POST[$field]) ? $temp = $_POST[$field] : $temp = '';
    $text .= $label . ' ' . $temp . '
';
  }
  mail( $youremail, $emailtitle, $text);
  echo $endmessage;
}

else
{
  echo '<form method="post" action="' . $action . '">';
  echo '<table>';

  foreach ($fields as $field => $label)
    echo '<tr><td>' , $label , '</td></tr><tr><td><input type="text" name="', $field , '" /></td></tr>';

  echo '<tr><td align="center"><input type="submit" name="submit" value="Send"></td></tr>';
  echo '</table>';
  echo '</form>';
}



Edit the top part of the code, including your email address, the title of the email you want to have sent to you, the fields you want to include in your form and what you want to say to your users after they fill it out.

akulion

great job we need one

u know u could add something to it to increase spam security - i saw it on one site somewhere...

its a simple thing i think...it is like this, at the end of the form is a question:

Please answer this question so we know you are a human being and not some spam bot:

What color is the button which says submit ?

Blue - green - purple - grey
(with check boxes)

not fool proof ofcourse but still pretty oki doki

JPDeni

In my first form script (which I found today and took the original code from) there's something similar, but then you have to have a bunch of other stuff in it, like rebuilding the form if they get it wrong. I didn't want to mess with it. (I'm feeling lazy. :) )

funxlab

#3
JPDeni,
Thanks for this, but the text fields size is quite small for message. I just noticed a problem with other code you gave me for name and phone number to admin by users. I am using same email address for both feeback and phone/Name forms so when I write a test feedback email and submitt I get two emails in my inbox. One is true feeback mail and second  is Phone/Name email  but only with this
Name:
Phone:
:o   :(


Regards,
Jim

SmokingYoDa

Hi,

I've been reading thro the forum and come across this thread & I want to give something back to TP community, so I hope this helps at least one person :)

I've been using an anti-spam form for a while on various sites, and it seems to be working well on all.

It can be found here - http://www.freecontactform.com

Quote from their site "Like you, we loath spammers. But we're so proud of our spam prevention script that we built this website so we can share it with you for free. Unlike most other CAPTCHA script, ours does not require special Server configurations and extentions, and is 100% accessible to all. It's also very easy to setup on just about any PHP hosts. Remember, if you have any problems, you can request free help in our support forums. Download our free contact us script today."


they have a demo on their site and we have it running here - http://www.unitedmoshers.com/index.php?page=Contact-UM

..all files are easily modified to suit your needs :)


I've not seen it used on many peoples sites so I hope I've not picked a duff, but like i say, its been working well so far on all sites I have put it on....and its FREE!

Hope this helps!!