html and php form 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
zsobell
Forum Newbie
Posts: 2
Joined: Tue Oct 07, 2008 2:52 pm

html and php form issues

Post by zsobell »

I am having trouble writing a simple script that will email me and the commenter the contents of their comment. Right now it looks like

Code: Select all

<?php
  $name = $_REQUEST['name'] ;
  $email = $_REQUEST['email'] ;
  $comment = $_REQUEST['comment'] ;
  
  $subject = 'a comment for you' ;
  $content = 'Comment:' ."\n" .$comment.
            .'From,' ."\n"
            .$name. ;
            
  $subject2 = 'Comment Confirmation' ;
  $content2 = 'Please do not reply.  This is an automated comment confirmation send by http://www.sobellium.com.' ."\n" ."\n"
            .$comment.
            .'From,' ."/n"
            .$name. ;
            
   mail( 'zach@sobell.com', $subject, $content, "From: $email") ;
   mail( $email, $subject2, $content2, "From: 'sobellium.com'") ;
   header( "Location: http://www.sobellium.com/contact" ) ;
?>
the error involves a "T_VARIABLE" on line 7

I'm sure its something blatantly obvious...
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Re: html and php form issues

Post by onion2k »

Your quotes and concatenation is a bit messed up.

What you have at the moment:

Code: Select all

$content = 'Comment:' ."\n" .$comment..'From,' ."\n".$name.;
What it should be:

Code: Select all

$content = 'Comment:\n'.$comment.'\nFrom,\n'.$name;
The way it works is that your closing quote needs to match the opening quote.. so if you open with ' you need to close with ', and between quoted blocks you should glue things together with periods (full stops) eg 'Text here'.$var.'more text here' ... Don't put a period at the end, or two periods next to each other.
zsobell
Forum Newbie
Posts: 2
Joined: Tue Oct 07, 2008 2:52 pm

Re: html and php form issues

Post by zsobell »

Thank you for your timely response (5 minutes...) and your help, although it appears that the ' quotes denote (at least in this case) output text, so i get a string that says, for example, "thank you,\nZach"

what is the correct way to solve this?

would this work:

Code: Select all

 $content = 'Comment:'."\n".$comment."\n".'From,'."\n".$name;
 
*edit -- it works. no need to reply unless there is a more correct way

thanks again
Post Reply