Jump to content

Help a newb with a contact form


mattyd949

Recommended Posts

I am setting up a personal website for me and my friends and am trying to do most of the work myself.  I purchased a template and I am customizing it.  I am having some issues with modifying the contact form script.  Here it is, if somebody can help point out where I should put my email address and mail server if needed, it would be greatly appreciated. thanks in advance.  You can use matt@email.com as the sample email address.

 

 

<?

Error_Reporting(E_ALL & ~E_NOTICE);

 

while ($request = current($_REQUEST)) {

if (key($_REQUEST)!='recipient') {

$pre_array=split ("&777&",  $request);

$post_vars[key($_REQUEST)][0]=$pre_array[0];

$post_vars[key($_REQUEST)][1]=$pre_array[1];

}

next($_REQUEST);

}

 

 

 

reset($post_vars);

 

 

$subject="From ".$post_vars['your_name'][0] ;

$headers= "From: ".$post_vars['your_email'][0] ."\n";

$headers.='Content-type: text/html; charset=iso-8859-1';

$message='';

  while ($mess = current($post_vars)) {

  if ((key($post_vars)!="i") && (key($post_vars)!="your_email") && (key($post_vars)!="your_name")) {

 

$message.="<strong>".$mess[1]."</strong>   ".$mess[0]."<br>";

}

next($post_vars);

}

 

mail($_REQUEST['recipient'], $subject,  "

<html>

<head>

<title>Contact letter</title>

</head>

<body>

<br>

  ".$message."

</body>

</html>" , $headers);

echo ("Your message was successfully sent!");

 

?>

<script>

resizeTo(300, 300);

</script>

 

Link to comment
Share on other sites

Scrap that. All you need to do is on the form which the form is submitting to use this:

 

<?

if (empty($_POST)) {
print "Error with form, please contact the webmaster.";
} else {


// Configuration Settings
$SendFrom =    "Contact Form <>";
$SendTo =      "emailaddress@email.com";
$SubjectLine = "Contact Form";
$ThanksURL =   "index.php";  //confirmation page
$Divider =     "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~";

// Build Message Body from Web Form Input
$MsgBody = @gethostbyaddr($REMOTE_ADDR) . "\n$Divider\n";
foreach ($_POST as $Field=>$Value)
   $MsgBody .= "$Field: $Value\n";
$MsgBody .= $Divider . "\n" . $HTTP_USER_AGENT . "\n";
$MsgBody = htmlspecialchars($MsgBody);  //make content safe

// Send E-Mail and Direct Browser to Confirmation Page



mail($SendTo, $SubjectLine, $MsgBody, "From: " . $SendFrom);
header("Location: $ThanksURL");
}
?>

 

This should be a lot easier for you.

Link to comment
Share on other sites

Thanks adamjblakey. This is working alot better.  Do you think you can help me remove &777& at the end of the fields?

 

sample email I am recieving

 

xxx.xxx.xxx.xxx

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

i: 4

your_name: Matt D&777&

your_email: matt@test.com&777&

message: test 123&777&

recipient: matt@mydomain.com

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)

 

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.