Jump to content

PHP Contact Form


mds

Recommended Posts

Hey guys I hope someone will be able to solve this for me. Basically I used a contact form generator but I tried editing it manually to add some more stuff into it, but got confused and wrecked it. I wanted to add a "Phone" field and "Name" field. After fiddling around, when I test the form, it gives me the all okay but I never received the email.

 

PLEASE PLEASE help me!

 

CONTACT.HTML

<form method="POST" id="captcha_form" name="captcha_form" action="mailform.php">
<div style="padding-bottom: 1em;">
  <table width="496" border="0" cellpadding="2" cellspacing="2" class="bodytext">
    <tr>
      <td width="99" valign="top">Please select:</td>
      <td width="383" valign="top"><select name="emailaddress" id="emailaddress">
        <option value=0 selected></option>
        <option value=1>Sales Enquiry</option>
        <option value=2>General Enquiry</option>
        <option value=3>Technical Enquiry</option>
      </select></td>
    </tr>
    <tr>
      <td width="99" valign="top">Full name:</td>
      <td valign="top"><input name="fullname" type="text" id="fullname" value="" size="30" /></td>
    </tr>
    <tr>
      <td width="99" valign="top">Phone Number:</td>
      <td valign="top"><input name="phone" type="text" id="phone" value="" size="30" /></td>
    </tr>
    <tr>
      <td valign="top">Email:</td>
      <td valign="top"><input name="email" type="text" id="email" value="" size="30" /></td>
    </tr>
    <tr>
      <td valign="top"><?php $subject = "Contact Enquiry"; ?></td>
      <td valign="top">Enter the text contained in the image into the text box: <br />
        <img src="captcha.php" /> <br />
        <input type="text" name="userpass" value="" /></td>
    </tr>
    <tr>
      <td valign="top">Message: </td>
      <td valign="top"><textarea name="message" id="message" rows="10" cols="50"></textarea></td>
    </tr>
    <tr>
      <td valign="top"> </td>
      <td valign="top"><input name="submit" type="submit" value="Submit" /></td>
    </tr>
  </table>
</form>

 

MAILFORM.PHP

 

<?php 
$dontsendemail = 0;
$possiblespam = FALSE;
$strlenmessage = "";
$fullname = $_REQUEST['fullname'];
$phone = $_REQUEST['phone'];
$email = $_REQUEST['email']; 
$message = $_REQUEST['message']; 
$subject = "Contact Enquiry";
$emailaddress = array(); /* NOTE: Although your email addresses
are visible here in this code, the person contacting you will never see these email addresses. 
Your email addresses will remain on your server, and they will not be sent from your server 
to the person contacting you. They will also remain invisible to spam bots. Your email addresses
are also never stored on any of our servers. You can choose to delete or not delete this note
when you publish this page. It will not change the functionality of the contact form. 
*/
$emailaddress[1] = "sales@removed";
	$emailaddress[2] = "admin@removed";
	$emailaddress[3] = "admin@removed";
	$contactnameindex = $_REQUEST['emailaddress'];
if ($contactnameindex == 0 || !isset($_REQUEST['emailaddress'])) print "<meta http-equiv=\"refresh\" content=\"0;URL=cerror.html\">";
else $emailaddress = $emailaddress[$contactnameindex];
function checkcaptcha() {
		session_start();
		if ($_SESSION["pass"] != $_POST["userpass"]) {
			print "<meta http-equiv=\"refresh\" content=\"0;URL=cerror.html\">";
			return 1;
		}
	}

function checkemail($field) {
// checks proper syntax
if( !preg_match( "/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/", $field))
{
	print "<meta http-equiv=\"refresh\" content=\"0;URL=cerror.html\">"; 
	return 1;
}
}
function spamcheck($field) {
if(eregi("to:",$field) || eregi("cc:",$field) || eregi("\r",$field) || eregi("\n",$field) || eregi("%0A",$field)){ 
	$possiblespam = TRUE;
}else $possiblespam = FALSE;
if ($possiblespam) {
	print "<meta http-equiv=\"refresh\" content=\"0;URL=cerror.html\">";
	return 1;
}
}
function strlencheck($field,$minlength,$whichfieldresponse) {
if (strlen($field) < $minlength){
	die($whichfieldresponse); 
	return 1;
}
}

	if ($dontsendemail == 0) $dontsendemail = checkcaptcha($email);

if ($dontsendemail == 0) $dontsendemail = checkemail($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($email);
if ($dontsendemail == 0) $dontsendemail = spamcheck($subject);
if ($dontsendemail == 0) $dontsendemail = strlencheck($email,10,"The email address field is too short. Please hit your browser back button and check your entry.<br />");

if ($dontsendemail == 0) $dontsendemail = strlencheck($message,10,"The message field is too short. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) $dontsendemail = strlencheck($emailaddress,8,"You have not selected a recipient of your message. Please hit your browser back button and check your entry.<br />");
if ($dontsendemail == 0) {mail($emailaddress,"Subject: $subject",$message,$fullname,$phone,"From: $email" ); print "<meta http-equiv=\"refresh\" content=\"0;URL=cokay.html\">";}
?>

 

I also have a CAPTCHA.PHP file but i don't think it's needed here. I ask you again, please help me out! Thanks in advance!

Link to comment
Share on other sites

<?php
$subject = $_POST['subject'];
$fromemail = $_POST['fromemail'];
$toemail = $_POST['toemail'];
$mainbox = $_POST['mainbox'];

mail( "$toemail", "$subject",
"$mainbox",
"From: $fromemail"
'Reply-To: $fromemail' );
header( "Location: whatever site u want" );
?>

This is a much more simple code. (the form is not included but it is very easy to make)

Link to comment
Share on other sites

<form method="post" action="wherever u saved the .php file">

<input name="fromemail" type="text" />

<input name="toemail" type="text" />

<input name="subject" type="text" />

<textarea name="mainbox"></textarea>

<input type="submit">

</form>

 

You could replace the toemail input with a dropdown menu

 

You could also set the fromemail to whatever you wanted using

<input name="fromemail" type="hidden" value="example@example.com" />

This would say that you recieved an email from example@example.com

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.