Current location: Hot Scripts Forums » Programming Languages » PHP » Help modifying contact form


Help modifying contact form

Reply
  #1 (permalink)  
Old 03-13-09, 04:32 PM
bally123 bally123 is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Help modifying contact form

Found a nice php contact form but would like to slightly ammend how the email is outputted. Currently it outputs
PHP Code:

$Field$Value 

but really I would like it to output like this
PHP Code:

$fname has made an enquiry about $subject


$fmess

Their contact details are
:
$fname
$fadd1
$fadd2
$fcity
$fpost

$fnumber
$femail 
This is the code for the contact form
PHP Code:

<?php

////////////////////////////////////////////////////////////////
// PERFECT                                                    //
// -------                                                    //
// PHP E-mail Receive Form Electronic Content Text            //
// File: feedback.php                                         //
// Version: 1.8 (April 21, 2008)                              //
// Description: Processes a web form to read the user input   //
//    and then send the data to a predefined recipient.  You  //
//    are free to use and modify this script as you like.     //
// Instructions:  Go to "http://www.centerkey.com/php".       //
// License: Public Domain Software                            //
//                                                            //
// Center Key Software  *  www.centerkey.com  *  Dem Pilafian //
////////////////////////////////////////////////////////////////

// Configuration Settings
$SendFrom =    "$fname <$femail>";
$SendTo =      "info@domain.tld";
$SubjectLine "$subject";
$ThanksURL =   "thanks.html";  //confirmation page

// Build Message Body from Web Form Input
foreach ($_POST as $Field=>$Value)
   
$MsgBody .= "$Field$Value\n";
$MsgBody htmlspecialchars($MsgBodyENT_NOQUOTES);  //make safe

// Send E-Mail and Direct Browser to Confirmation Page
      
if (count($_POST) > 0)
      
$Spam count($_POST) == || stristr($MsgBody"cc: ") ||
          
stristr($MsgBody"href=") || stristr($MsgBody"[url");
      if (!
$Spam)
          
mail($SendTo$SubjectLine$MsgBody"From: $SendFrom"); 
header("Location: $ThanksURL");
?>
Iv tried loads of different ways but I dont really know what im doing and think it has someting to do with the foreach bit
Reply With Quote
  #2 (permalink)  
Old 03-13-09, 05:46 PM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
You could replace the foreach loop with something like this:

PHP Code:

$MsgBody=<<< END

{
$_POST['fname']} has made an enquiry about {$_POST['subject ']}

{$_POST['fmess']} 

Their contact details are: 
{$_POST['f'name']}
... (etc)

END; 
Reply With Quote
  #3 (permalink)  
Old 03-13-09, 06:40 PM
bally123 bally123 is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks will give that a try
Reply With Quote
  #4 (permalink)  
Old 03-13-09, 07:03 PM
bally123 bally123 is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Doesnt appear to work not sure if im doing it wrong but tried
PHP Code:

foreach ($_POST as $Field=>$Value
$MsgBody=<<< END 
{$_POST['fname']} has made an enquiry about {$_POST['subject']} 

{
$_POST['fmess']}  

Their contact details are:  
{
$_POST['fname']} 
 
END
Which gives the following error:
Quote:
Parse error: syntax error, unexpected T_SL in /mnt/w0108/d10/s10/b028bc78/www/domain.tld/test.php on line 25
and also tried
PHP Code:

$MsgBody=<<< END 

{$_POST['fname']} has made an enquiry about {$_POST['subject']} 

{
$_POST['fmess']}  

Their contact details are:  
{
$_POST['fname']} 
 
END
Which gives same error...
Reply With Quote
  #5 (permalink)  
Old 03-14-09, 10:46 AM
wirehopper's Avatar
wirehopper wirehopper is offline
-
 
Join Date: Feb 2006
Posts: 2,515
Thanks: 20
Thanked 109 Times in 106 Posts
Might be the =<<< END - try =<<<END
Reply With Quote
  #6 (permalink)  
Old 03-14-09, 01:38 PM
bally123 bally123 is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Still gives same error message
Reply With Quote
  #7 (permalink)  
Old 03-14-09, 10:08 PM
zamight zamight is offline
New Member
 
Join Date: Mar 2009
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Take away all whitespace's from the end of END;.
There can't be anything after the END;
Reply With Quote
  #8 (permalink)  
Old 03-15-09, 04:41 AM
bally123 bally123 is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks that worked its amazing how a little white space makes all the difference.
Reply With Quote
  #9 (permalink)  
Old 03-15-09, 05:45 AM
bally123 bally123 is offline
Newbie Coder
 
Join Date: Jul 2006
Posts: 63
Thanks: 0
Thanked 0 Times in 0 Posts
Finally all working perfectly just another quick question if anyone is able to help, is there a way of someone else using my mailform.php from another site if so how can I prevent them from doing this?

For example only submit form if enquiry has come from mysite/enquiry.html
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
ajax checking and onsubmit issue follower JavaScript 4 10-12-08 03:45 PM
Problem with FormMail script for simple contact form amang Perl 2 09-21-07 07:59 PM
Tute: Create Email based Contact Form Grabber PHP 3 05-31-06 03:11 AM
Contact Form w/ Database Fuyuki Script Requests 0 01-13-06 10:50 AM


All times are GMT -5. The time now is 08:30 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.