PHP Contact Form

death180

Seasoned Veteran
Joined
Jul 3, 2009
Messages
4,338
Reaction score
0
FP$
1,767
I need a working PHP contact form, and not from one of the generators online. But the source code.

Thanks to whoever tries to help
 
Here is what you are looking for, just copy it to notepad and fill in your email at the top. Then save and upload. Let me know if you need any help. I have mine saved as submitemail.php.

Code:
<?

/************************
* Variables you can change
*************************/

$mailto = "[email protected]";
$cc = "";
$bcc = "";
$subject = "Email subject";
$vname = "BrightCherry enquiry";


/************************
* do not modify anything below unless you know PHP/HTML/XHTML
*************************/


$email = $_POST['email'];

function validateEmail($email)
{
   if(eregi('^[a-zA-Z0-9._-]+@[a-zA-Z0-9-]+\.[a-zA-Z]{2,4}(\.[a-zA-Z]{2,3})?(\.[a-zA-Z]{2,3})?$', $email))
	  return true;
   else
	  return false;
}


if((strlen($_POST['name']) < 1 ) || (strlen($email) < 1 ) || (strlen($_POST['message']) < 1 ) || validateEmail($email) == FALSE){
	$emailerror .= '';

	if(strlen($_POST['name']) < 1 ){
		$emailerror .= '<li>Enter name</li>';
	}

	if(strlen($email) < 1 ){
		$emailerror .= '<li>Enter email</li>';
	}

	if(validateEmail($email) == FALSE) {
		$emailerror .= '<li>Enter valid email</li>';
	}

	if(strlen($_POST['message']) < 1 ){
		$emailerror .= '<li>Enter message</li>';
	}

} else {

	$emailerror .= "Your email has been sent successfully";



	// NOW SEND THE ENQUIRY

	$timestamp = date("F j, Y, g:ia");

	$messageproper ="\n\n" .
		"Name: " .
		ucwords($_POST['name']) .
		"\n" .
		"Email: " .
		ucwords($email) .
		"\n" .
		"Website: " .
		ucwords($_POST['website']) .
		"\n" .
		"Company: " .
		ucwords($_POST['company']) .
		"\n" .
		"Comments: " .
		$_POST['message'] .
		"\n" .
		"\n\n" ;

		$messageproper = trim(stripslashes($messageproper));
		mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['e_mail'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['e_mail'].">\nX-Mailer: PHP/" . phpversion() );

}
?>

<div id='emailerror'>
	<ul>
		<? echo $emailerror; ?>
	</ul>
</div>

The here is the HTML you can put where you want it on the website:

Code:
	<h2>Here you can send us a message!</h2>
            <p>Random text paragraph here!</p>
            <h3>General Support</h3>
            <form action="submitemail.php" id="submitform" method="post">
  <ul>
  	<li class="forminput">
    	<ul>
        	<li class="formleft">Name:</li>
        	<li class="formright"><input name="name" type="text"/> *</li>
         </ul>
     </li>
     <li class="forminput">
    	<ul>
        <li class="formleft">Email:</li>
    <li class="formright"><input name="email" type="text"/> *</li>
      </ul>
     </li>
    <li class="forminput">
    	<ul>
        <li class="formleft">Website:</li>
      <li class="formright"><input name="website" type="text"/></li>
        </ul>
     </li>
      <li class="forminput">
    	<ul> 
        <li class="formleft">Company:</li>
        <li class="formright"><input name="company" type="text"/></li>
          </ul>
     </li>
        <li class="forminput">
    	<ul>
        <li class="formleft">Message/Comment:</li>
        <li class="formright"><textarea name="message" cols="40" rows="5"></textarea> * </li>
        
          </ul>
     </li>
     <li class="forminput">
     	<ul>
        	<li class="formleft hidden">Submit</li>
        	<li class="formright"><input type="submit" class="button" value="Submit" /></li>
        </ul>
     </li>
        </ul>
  </form>
 
After I sent it I got htis error:

Code:
# Enter name'; } if(strlen($email) < 1 ){ $emailerror .= 'Enter email
# '; } if(validateEmail($email) == FALSE) { $emailerror .= 'Enter valid email
# '; } if(strlen($_POST['message']) < 1 ){ $emailerror .= 'Enter message
'; } } else { $emailerror .= "Your email has been sent successfully"; // NOW SEND THE ENQUIRY $timestamp = date("F j, Y, g:ia"); $messageproper ="\n\n" . "Name: " . ucwords($_POST['name']) . "\n" . "Email: " . ucwords($email) . "\n" . "Website: " . ucwords($_POST['website']) . "\n" . "Company: " . ucwords($_POST['company']) . "\n" . "Comments: " . $_POST['message'] . "\n" . "\n\n" ; $messageproper = trim(stripslashes($messageproper)); mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['e_mail'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['e_mail'].">\nX-Mailer: PHP/" . phpversion() ); } ?>
 
death180 said:
After I sent it I got htis error:

Code:
# Enter name'; } if(strlen($email) < 1 ){ $emailerror .= 'Enter email
# '; } if(validateEmail($email) == FALSE) { $emailerror .= 'Enter valid email
# '; } if(strlen($_POST['message']) < 1 ){ $emailerror .= 'Enter message
'; } } else { $emailerror .= "Your email has been sent successfully"; // NOW SEND THE ENQUIRY $timestamp = date("F j, Y, g:ia"); $messageproper ="\n\n" . "Name: " . ucwords($_POST['name']) . "\n" . "Email: " . ucwords($email) . "\n" . "Website: " . ucwords($_POST['website']) . "\n" . "Company: " . ucwords($_POST['company']) . "\n" . "Comments: " . $_POST['message'] . "\n" . "\n\n" ; $messageproper = trim(stripslashes($messageproper)); mail($mailto, $subject, $messageproper, "From: \"$vname\" <".$_POST['e_mail'].">\nReply-To: \"".ucwords($_POST['first_name'])."\" <".$_POST['e_mail'].">\nX-Mailer: PHP/" . phpversion() ); } ?>

Not sure mate, but that is the one that I use.
 
Alot of these aren't secure, which is one reason why I don't use contact forms, unless I make it myself and have tested it.
 
I did what Justin said, now I get this error when I submit:

Code:
Deprecated: Function eregi() is deprecated in C:\wamp\www\death18012\submitemail.php on line 23

Notice: Undefined variable: emailerror in C:\wamp\www\death18012\submitemail.php on line 51

Notice: Undefined index: e_mail in C:\wamp\www\death18012\submitemail.php on line 78

Notice: Undefined index: first_name in C:\wamp\www\death18012\submitemail.php on line 78

Notice: Undefined index: e_mail in C:\wamp\www\death18012\submitemail.php on line 78

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\death18012\submitemail.php on line 78
<br /><br />-- January 28th, 2011, 2:49 pm --<br /><br />I did what Justin said, now I get this error when I submit:

Code:
Deprecated: Function eregi() is deprecated in C:\wamp\www\death18012\submitemail.php on line 23

Notice: Undefined variable: emailerror in C:\wamp\www\death18012\submitemail.php on line 51

Notice: Undefined index: e_mail in C:\wamp\www\death18012\submitemail.php on line 78

Notice: Undefined index: first_name in C:\wamp\www\death18012\submitemail.php on line 78

Notice: Undefined index: e_mail in C:\wamp\www\death18012\submitemail.php on line 78

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\death18012\submitemail.php on line 78
 
Hey Death180, PM me and I'll give the code that I use on mine, it's secure and works very well. It also has a check feature to make sure all fields are filled out.
 
Back
Top Bottom