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 [email protected] 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
https://forums.phpfreaks.com/topic/57563-help-a-newb-with-a-contact-form/
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 =      "[email protected]";
$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.

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: [email protected]&777&

message: test 123&777&

recipient: [email protected]

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

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

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.