Contact Form

Here’s the contact form. You can integrate the form with you website if you want.

[COLOR=“Silver”]contact.html[/COLOR]


<form method="POST" action="mailer.php">
Name<br />
<input type="text" name="name" size="30" value="" class="text-input" />
<br />
Email<br />
<input type="text" name="email" id="email" size="30" value="" class="text-input" />
<br />
Your Message<br />
<textarea cols="25" rows="8" name="message" class="text-input"></textarea>
<br />
<input type="submit" value="Send Email" name="submit" class="button" id="submit_btn">
</form>

[COLOR=“Silver”]mailer.php[/COLOR]

<?php
$to = "your@emailhere.com";
$subject = "Support requested by ".$_POST['name'];
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

$headers = 'From: '.$_POST['email'].'' . "
" .
   'Reply-To: '.$_POST['email'].'' . "
" .
   'X-Mailer: PHP/' . phpversion();
 
$body = $message;

mail($to, $subject, $body, $headers );
header( 'Location: http://www.landingpage.html' ) ; //replace with landing page.
?> 

Hi,

Thanks for the suggestion. I commented that there is a way that the code “PHP” would be nicer in this forum. You can use BBCode writing the code within [ php] and [ /php] (similar to how you did with the HTML code).

Thanks for that Ribbit, guess what, I tried it, and it works! Looking at it, it almost looks like the form can be expanded to have other things on it as well. Would you like to trade links?

Original post updated with PHP BBCodes :slight_smile:

Haha thanks

@3dsmaxmaster, I would love to trade links except there’s currently no space on my website. It would look out of place. Once I find a place, I’d be glad to!

Hey cool, thanks Ribb, I need one of those on my site as well.

On a somewhat related question, will putting my email address into the .php file open it up to harvesters to send spam to? I know that a mailto: in an .html file will, but I’m not sure if they harvest them from .php files as well.

I know it’s probably too late for this but there is no way that an email harvester can grab this email in your php file. It is completely hidden from the end user. However, if you are really scared, you can make another email and have it forwarded to your main email. That way, you can just stop the forwarding if you are being spammed.

What do you use for the “landing page” on these forms? I made a guess and emailed myself 18 times in one minute, so I thought I’d ask.

You just tell the person if the email was succesful, maybe a link to the home, maybe a message telling them how long it will take, just anything you want!

the code u gave is a very useful but simple. u can use a html contact from with capctha,
following is the code if u want to use

The contact form with CAPTCHA

Here is the HTML code for the contact form:


<form method="POST" name="contact_form"
action="<?php echo htmlentities($_SERVER['PHP_SELF']); ?>">
<label for="name">Name: </label>
<input type="text" name="name"
value="<?php echo htmlentities($name) ?>">
<label for="email">Email: </label>
<input type="text" name="email"
value="<?php echo htmlentities($visitor_email) ?>">
<label for="message">Message:</label>
<textarea name="message" rows=8 cols=30
><?php echo htmlentities($user_message) ?></textarea>
<img src="captcha_code_file.php?rand=<?php echo rand(); ?>"
id="captchaimg" >
<label for="message">Enter the code above here :</label>
<input id="6_letters_code" name="6_letters_code" type="text">
<input type="submit" value="Submit" name="submit">
</form>

The HTML form above contains the fields for name, email and message. In addition, we have the CAPTCHA image. The tag for the CAPTCHA image points to the script captcha_code_file.php. The PHP script in ‘captcha_code_file.php’ creates the image for the captcha and saves the code in a session variable named ‘6_letters_code’.

Validating the CAPTCHA

When the form is submitted, we compare the value in the session variable(6_letters_code) with the submitted CAPTCHA code( the value in the text field 6_letters_code). If the codes match, then we proceed with emailing the form submission. Else we display an error.

Here is the code that does the server side processing:


<?php
if(isset($_POST['submit']))
{
  if(empty($_SESSION['6_letters_code'] ) ||
    strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0)
  {
      //Note: the captcha code is compared case insensitively.
      //if you want case sensitive match, update the check above to
      // strcmp()
    $errors .= "
 The captcha code does not match!";
  }
  if(empty($errors))
  {
    //send the email
    $to = $your_email;
    $subject="New form submission";
    $from = $your_email;
    $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
    $body = "A user  $name submitted the contact form:
".
    "Name: $name
".
    "Email: $visitor_email 
".
    "Message: 
 ".
    "$user_message
".
    "IP: $ip
";
    $headers = "From: $from 
";
    $headers .= "Reply-To: $visitor_email 
";
    mail($to, $subject, $body,$headers);
    header('Location: thank-you.html');
  }
}
?>

Customizing the CAPTCHA

The CAPTCHA script in the sample code download can be customized. If you open the script, you can see the first few lines of the code as shown below:


$image_width = 120;
$image_height = 40;
$characters_on_image = 6;
$font = './monofont.ttf';
//The characters that can be used in the CAPTCHA code.
//avoid confusing characters (l 1 and i for example)
$possible_letters = '23456789bcdfghjkmnpqrstvwxyz';
$random_dots = 0;
$random_lines = 20;
$captcha_text_color="0x142864";
$captcha_noise_color = "0x142864";

You can change the size of the CAPTCHA by changing $image_width & $image_height. The number of characters in the CAPTCHA can be changed by updating $characters_on_image. Similarly, the text color of the CAPTCHA can be customized by updating $captcha_text_color. The code adds some ‘noise’ in the image by adding random lines and dots. you can increase or decrease the noise. Please note that increasing the noise may make it difficult for your genuine visitors to read the code.

THANK you! This will be a huge help.

Hi, I’m new with php.
I tried copy&paste the html and php files ,which was posted by RibbitHost on 7/3/2011, on to my website and uploaded both, but it didn’t work for me. When I input contact form and click send, I get error and connect to 000webhost site.
In order for form to work, i need to upload the html form file and the php files, right?

I’ve been trying to figure out php form for days. Can any body help me?:confused:

I don’t quite understand what you mean, tomyam.

I wound up going to mycontactform.com. Their version worked.

Thank you. I will give it a try!:slight_smile:

i got it working but when submit is clicked it submits the message to my email but the page redirects to error 404

[24 minutes later]

its ok i fixed it now seems i typed the landing page address wrong

Hi All,

Can i know how can i get additional information to show on the body? Currently, the code posted by RibbitHost only shows the information entered under “Message”. I can’t the body to show others information like Name and Email.

Appreciate for any help offer :slight_smile:

Stanley

I’ve been trying to get a simple Form or even a Form with Captcha through Dreamweaver.

I’ve googled and inserted about 5 different Forms and Captchas and even sent a ticket to Admin, but I just can’t figure it out.

I’d love some help please, advice, scripts - anything.

I’m a newbie and need confirmation I’ve called the files the right ending.
Thanks
SonicX

my site: http://www.sonicxplosion.com

Form found at: http://www.sonicxplosion.com/contact.html (I’ve tried html and php and neither work as extensions, using the same internal script)

http://www.sonicxplosion.com/mailer.php

http://www.sonicxplosion.com/verificationimage.php

I have found the answer to my problems - my ooowebhost server #43 is now not pushing emails from contact forms. For the past 2 years it was fine, now for some reason it’s not working.

I can send and receive from my own domain name ooowebhost email but zero emails from my website contact form since I replaced my flash website working contact form to a html / php site with a contact form.

As mentioned above I lodged an eTicket but they just said contact forms using php and captcha are supported on ooowebhost.

After much research I tested my ooowebhost server sending emails via the below mailtest.php link and inserted my Hotmail then gmail then ooowebhost email addresses - zero were received.

http://server43.000webhost.com/mailtest.php

I then tested the other servers I have sites on - and happy days, I received every single email sent. So…server 43 is the problem. I’ve lodged a second eTicket for help. If there isn’t anything that can be done, I’ll pull down the site, click create a new site in cPanel and point my domain name servers to the new ooowebhost server.

If you want to check if your ooowebhost server does not send emails from contact forms just look up which server you are on in cPanel, then insert your number where the # is below:

http://server#.000webhost.com/mailtest.php

For example:
http://server11.000webhost.com/mailtest.php [working]

http://server37.000webhost.com/mailtest.php [working]

There are about 40 servers on ooowebhost, so if yours doesn’t work, change.

Good luck.
SonicX

Normally I use pluggin contact form 7 for wordpress. It saves my time.