PHP Contact Form HELP PLEASE!!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
xfile102
Forum Newbie
Posts: 1
Joined: Sat Jun 30, 2012 10:02 am

PHP Contact Form HELP PLEASE!!

Post by xfile102 »

I can really use a hand. I am trying to setup the contact form for my site, and I dont know PHP. The Form is basically:

First Name*
Email*
Company
Subject
Message*

Submit Button

The fields with Asterisks are REQUIRED fields. I found some PHP code online but it makes no sense.

Here is the PHP form Code

<?php

if(!$_POST) exit;

$email = $_POST['email'];

//$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
$error.="Invalid email address entered";
$errors=1;
}
if($errors==1) echo $error;
else{
$values = array ('name','email','message');
$required = array('name','email','message');

$your_email = "james@example.com";
$email_subject = "New Message: ".$_POST['subject'];
$email_content = "new message:\n";

foreach($values as $key => $value){
if(in_array($value,$required)){
if ($key != 'subject' && $key != 'company') {
if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
}
$email_content .= $value.': '.$_POST[$value]."\n";
}
}

if(@mail($your_email,$email_subject,$email_content)) {
echo 'Message sent!';
} else {
echo 'ERROR!';
}
}
?>

Can someone please help me figure out what to put where?
User avatar
califdon
Jack of Zircons
Posts: 4484
Joined: Thu Nov 09, 2006 8:30 pm
Location: California, USA

Re: PHP Contact Form HELP PLEASE!!

Post by califdon »

I doubt that you will get much help here with such a general question, and considering that you "don't know PHP". That's asking a lot. You might try posting in our Volunteer Work forum.
Post Reply