PHP form field issues

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Eyewolf
Forum Newbie
Posts: 4
Joined: Sun Mar 20, 2005 4:18 pm

PHP form field issues

Post by Eyewolf »

Hi, I am a php novice and got a generated form from another web site for a site I am doing. I was told I could add additional fields to my form and shown an example of how to do it. I added 2 fields and it worked fine, but when I added more it stopped working.

Below is the code that works, and then the same code with additional fields which does not work. I would really appreciate some help!

Code: Select all

<?

// $mailto - set to the email address you want the form
// sent to, eg
//$mailto		= &quote;youremailaddress@example.com&quote; ;

$mailto = 'john@eyewolfdesign.com' ;

// $subject - set to the Subject line of the email, eg
//$subject	= &quote;Feedback Form&quote; ;

$subject = &quote;Email From Web Site&quote; ;

// the pages to be displayed, eg
//$formurl		= &quote;http://www.example.com/feedback.html&quote; ;
//$errorurl		= &quote;http://www.example.com/error.html&quote; ;
//$thankyouurl	= &quote;http://www.example.com/thankyou.html&quote; ;

$formurl = &quote;http://www.eyewolfdesign.com/nutkingdom/contact.htm&quote; ;
$errorurl = &quote;http://www.nutkingdom.com/error.htm&quote; ;
$thankyouurl = &quote;http://www.nutkingdom.com/thanks.htm&quote; ;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$topic = $_POSTї'topic'] ;
$company = $_POSTї'company'] ;
$name = $_POSTї'name'] ;
$email = $_POSTї'email'] ;
$comments = $_POSTї'comments'] ;
$http_referrer = getenv( &quote;HTTP_REFERER&quote; );

if (!isset($_POSTї'email'])) {
	header( &quote;Location: $formurl&quote; );
	exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
   header( &quote;Location: $errorurl&quote; );
   exit ;
}
if (get_magic_quotes_gpc()) {
	$comments = stripslashes( $comments );
}

$messageproper =

	&quote;This message was sent from:\n&quote; .
	&quote;$http_referrer\n&quote; .
	&quote;------------------------- COMMENTS -------------------------\n\n&quote; .
	$comments .
	&quote;\n\n------------------------------------------------------------\n&quote; ;

mail($mailto, $subject, &quote;$messageproper\nTopic: $topic\n&quote;, &quote;\nCompany Name: $company\n&quote;, &quote;From: \&quote;$name\&quote; <$email>\nReply-To: \&quote;$name\&quote; <$email>\nX-Mailer: chfeedback.php 2.03&quote; );
header( &quote;Location: $thankyouurl&quote; );
exit ;

?>

Code: Select all

<?

// $mailto - set to the email address you want the form
// sent to, eg
//$mailto		= &quote;youremailaddress@example.com&quote; ;

$mailto = 'john@eyewolfdesign.com' ;

// $subject - set to the Subject line of the email, eg
//$subject	= &quote;Feedback Form&quote; ;

$subject = &quote;Email From Web Site&quote; ;

// the pages to be displayed, eg
//$formurl		= &quote;http://www.example.com/feedback.html&quote; ;
//$errorurl		= &quote;http://www.example.com/error.html&quote; ;
//$thankyouurl	= &quote;http://www.example.com/thankyou.html&quote; ;

$formurl = &quote;http://www.eyewolfdesign.com/nutkingdom/contact.htm&quote; ;
$errorurl = &quote;http://www.nutkingdom.com/error.htm&quote; ;
$thankyouurl = &quote;http://www.nutkingdom.com/thanks.htm&quote; ;

// -------------------- END OF CONFIGURABLE SECTION ---------------

$topic = $_POSTї'topic'] ;
$company = $_POSTї'company'] ;
$name = $_POSTї'name'] ;
$email = $_POSTї'email'] ;
$address = $_POSTї'address'] ;
$city = $_POSTї'city'] ;
$state = $_POSTї'state'] ;
$zip = $_POSTї'zip'] ;
$phone = $_POSTї'phone'] ;
$fax = $_POSTї'fax'] ;
$user = $_POSTї'user'] ;
$catalog = $_POSTї'catalog'] ;
$prices = $_POSTї'prices'] ;
$comments = $_POSTї'comments'] ;
$http_referrer = getenv( &quote;HTTP_REFERER&quote; );

if (!isset($_POSTї'email'])) {
	header( &quote;Location: $formurl&quote; );
	exit ;
}
if (empty($name) || empty($email) || empty($comments)) {
   header( &quote;Location: $errorurl&quote; );
   exit ;
}
if (get_magic_quotes_gpc()) {
	$comments = stripslashes( $comments );
}

$messageproper =

	&quote;This message was sent from:\n&quote; .
	&quote;$http_referrer\n&quote; .
	&quote;------------------------- COMMENTS -------------------------\n\n&quote; .
	$comments .
	&quote;\n\n------------------------------------------------------------\n&quote; ;

mail($mailto, $subject, &quote;$messageproper\nTopic: $topic\n&quote;, &quote;\nCompany Name: $company\n&quote;, 
&quote;\nAddress: $address\n&quote;, &quote;\nCity: $city\n&quote;, &quote;\nState: $state\n&quote;, &quote;\nZip: $zip\n&quote;, 
&quote;\nPhone: $phone\n&quote;, &quote;\nFax: $fax\n&quote;, &quote;\nUser: $user\n&quote;, &quote;\nSend Catalog: $catalog\n&quote;, 
&quote;\nPrice List: $prices\n&quote;, &quote;From: \&quote;$name\&quote; <$email>\nReply-To: \&quote;$name\&quote; <$email>\nX-Mailer: chfeedback.php 2.03&quote; );
header( &quote;Location: $thankyouurl&quote; );
exit ;

?>

feyd | Please review how to post code using

Code: Select all

and

Code: Select all

tags. Read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url][/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

define "not working"

You're sending 1 too many arguments to mail in the first code, and many more in the second. You need to construct a SINGLE string for all the message you wish to send.
Eyewolf
Forum Newbie
Posts: 4
Joined: Sun Mar 20, 2005 4:18 pm

PHP form field issues

Post by Eyewolf »

Thanks for replying.

What happens is with the first code, I am able to receive an email with the field entries, but on the second (with more fields) I do not.

I have no idea how to construct a single string, I'm pretty new to php. Your help is appreciated!
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

string information

$messageproper in your first post is the bulk of the correct message. $company may appear in the message text, however it is not correct.. because From: will be wrong, along with X-Mailer.

mail() takes up to 5 arguements.
  1. to address
  2. subject string
  3. message string
  4. headers
  5. extra parameters for sendmail
Eyewolf
Forum Newbie
Posts: 4
Joined: Sun Mar 20, 2005 4:18 pm

Post by Eyewolf »

I'm sorry, I still don't understand how I should write it. I see what you mean about the arguments (I believe there are 5), but if I can't put these fields inside the arguments, where do they go?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

read how strings work (the first link in my previous post)
Eyewolf
Forum Newbie
Posts: 4
Joined: Sun Mar 20, 2005 4:18 pm

Post by Eyewolf »

I have a better understanding now, but I found no references to adding fields and where and how I would write them, sorry.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

"concat" or "concatenate"

it's a string operator. noted by the dot.. look carefully at your first code block. $messageproper uses the concat operator to stich together a string.

The stuff you are using, should only use 4 arguments to mail().. not 5 by the way.
Post Reply