469,332 Members | 6,649 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,332 developers. It's quick & easy.

Can't send message

I'm filling out forms on one page, then trying to send an
email and print out the vars on the next page.

Q1: Whenever I insert the mail script, it gives me a parse error.
Please point out my syntax errors, etc.

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or
`T_NUM_STRING' in /mypathhere/proposalconfirm.php on line 2

--script in question
<? session_start();
$msg = "x x proposal for:\n\t$_POST['cpname'],\t$_POST['cptitle']\n";
$msg .= "\t$_POST['cpcomp']\n";
$msg .= "\tAddress:\t$_POST['cpaddress']\n";
$msg .= "\t$_POST['cpcity'], $_POST['cpstate']\t$_POST['cpzip']\n";
$mailheaders = "From: company name here\n";
$mailheaders = "CC: $_POST['cpemail']";
mail("me@my.com","x x Custom Proposal",$msg,$mailheaders);
?>
<html>
--rest of script--

The printing of all vars works fine (once I removed the double
quotes from the post var callouts)

Q2: Do I need sessions to track the form vars from page to page
or am I adding unnecessary complexity to this?

My last large PHP dev work was about 2 years ago. Since then,
quick and dirty flatfile database connections (member lists)
are all I've had to contend with. Things have really changed
with PHP and MySQL in that time.

Thanks in advance for the help.

Jul 17 '05 #1
11 3333

On 6-Oct-2003, Larry Jaques <jake@di\/ersify.com> wrote:
I'm filling out forms on one page, then trying to send an
email and print out the vars on the next page.

Q1: Whenever I insert the mail script, it gives me a parse error.
Please point out my syntax errors, etc.

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or
`T_NUM_STRING' in /mypathhere/proposalconfirm.php on line 2

--script in question
<? session_start();
$msg = "x x proposal for:\n\t$_POST['cpname'],\t$_POST['cptitle']\n";
$msg .= "\t$_POST['cpcomp']\n";
$msg .= "\tAddress:\t$_POST['cpaddress']\n";
$msg .= "\t$_POST['cpcity'], $_POST['cpstate']\t$_POST['cpzip']\n";
$mailheaders = "From: company name here\n";
$mailheaders = "CC: $_POST['cpemail']";
mail("me@my.com","x x Custom Proposal",$msg,$mailheaders);
?>


The script you posted compiles without syntax errors. It does have a problem
in that the array subscripts inside a double quoted string should not have
single quotes around them. That is it should be "\t$_POST[cpcomp]\n". Also,
the second line starting with '$mailheaders =' should be '$mailheaders .='

Another problem is you don't seem to be validating anything, leaving
yourself open to abuse.

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #2
On Tue, 07 Oct 2003 05:54:50 GMT, "Tom Thackrey"
<us***********@nospam.com> pixelated:

On 6-Oct-2003, Larry Jaques <jake@di\/ersify.com> wrote:
I'm filling out forms on one page, then trying to send an
email and print out the vars on the next page.

Q1: Whenever I insert the mail script, it gives me a parse error.
Please point out my syntax errors, etc.

Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or
`T_NUM_STRING' in /mypathhere/proposalconfirm.php on line 2

--script in question
<? session_start();
$msg = "x x proposal for:\n\t$_POST['cpname'],\t$_POST['cptitle']\n";
$msg .= "\t$_POST['cpcomp']\n";
$msg .= "\tAddress:\t$_POST['cpaddress']\n";
$msg .= "\t$_POST['cpcity'], $_POST['cpstate']\t$_POST['cpzip']\n";
$mailheaders = "From: company name here\n";
$mailheaders = "CC: $_POST['cpemail']";
mail("me@my.com","x x Custom Proposal",$msg,$mailheaders);
?>
The script you posted compiles without syntax errors. It does have a problem
in that the array subscripts inside a double quoted string should not have
single quotes around them. That is it should be "\t$_POST[cpcomp]\n". Also,
the second line starting with '$mailheaders =' should be '$mailheaders .='


Arrrgh! 'Twas the concatenation dot missing which did me in.
I ran it from an earlier version with the $cpname vs. the
$_POST[cpname] and it works fine. Which is safer?

Another problem is you don't seem to be validating anything, leaving
yourself open to abuse.


True, I need to add validation!

Thanks for catching my cat, Tom. Now I can get some sleep.
;)

Jul 17 '05 #3
With total disregard for any kind of safety measures "Tom
Thackrey" <us***********@nospam.com> leapt forth and uttered:
The script you posted compiles without syntax errors. It does
have a problem in that the array subscripts inside a double
quoted string should not have single quotes around them. That is
it should be "\t$_POST[cpcomp]\n".


Incorrect, all array keys should be quoted unless you're passing
a constant. If PHP sees an unquoted array key it has to check to
make sure it isn't a constant before processing it and will
throw a Notice error.

Corrected code:

<?php
session_start();
$msg = "x x proposal for:\n\t{$_POST['cpname']},\t{$_POST['cptitle']}\n";
$msg .= "\t{$_POST['cpcomp']}\n";
$msg .= "\tAddress:\t{$_POST['cpaddress']}\n";
$msg .= "\t{$_POST['cpcity']}, {$_POST['cpstate']}\{t$_POST['cpzip']}\n";

$mailheaders = "From: company name here\n";
$mailheaders = "CC: {$_POST['cpemail']}";

mail("me@my.com","x x Custom Proposal",$msg,$mailheaders);
?>

PHP does not register array values when placed in double-quoted strings.
In order for this to work they require bracketing with {} or escaping from
the string altogether.

--
There is no signature.....
Jul 17 '05 #4

On 7-Oct-2003, Phil Roberts <ph*****@HOLYflatnetSHIT.net> wrote:
With total disregard for any kind of safety measures "Tom
Thackrey" <us***********@nospam.com> leapt forth and uttered:
The script you posted compiles without syntax errors. It does
have a problem in that the array subscripts inside a double
quoted string should not have single quotes around them. That is
it should be "\t$_POST[cpcomp]\n".


Incorrect, all array keys should be quoted unless you're passing
a constant. If PHP sees an unquoted array key it has to check to
make sure it isn't a constant before processing it and will
throw a Notice error.


Not true. Array references inside double quotes behave differently. Inside
double quotes $a[b] is the same as {$a['b']} and constant lookup is not
done.

From the doc:
// Works but note that this works differently outside string-quotes
echo "A banana is $fruits[banana].";
// Works
echo "A banana is {$fruits['banana']}.";
// Works but PHP looks for a constant named banana first
// as described below.
echo "A banana is {$fruits[banana]}.";
// Won't work, use braces. This results in a parse error.
echo "A banana is $fruits['banana'].";
http://www.php.net/manual/en/languag...parsing.simple

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #5
On Tue, 07 Oct 2003 04:10:35 -0500, Phil Roberts
<ph*****@HOLYflatnetSHIT.net> pixelated:
With total disregard for any kind of safety measures "Tom
Thackrey" <us***********@nospam.com> leapt forth and uttered:
The script you posted compiles without syntax errors. It does
have a problem in that the array subscripts inside a double
quoted string should not have single quotes around them. That is
it should be "\t$_POST[cpcomp]\n".
Incorrect, all array keys should be quoted unless you're passing
a constant. If PHP sees an unquoted array key it has to check to
make sure it isn't a constant before processing it and will
throw a Notice error.


Taking both sets of advice, I came up with:

<td align=left><font face="tahoma,arial" size="-1"><? echo
"{stripslashes($_POST['cpcity'])} , {$_POST['cpstate']}
{$_POST['cpzip']}" ?></td></tr> (browser wrap)

This didn't work until I removed the quotes from 'cpcity'.
This now displays: "City: {stripslashes(Cityfield)} , ST 45678"
where the input was "Cityfield", "ST", and "45678".
When I removed the curly braces from city, it gave the
same output (sans curly braces.)

The double quotes allowed me to place the comma.

This page is taking between 12 and 15 seconds to render, too.
Is echoing the entire script quicker than individual calls
to PHP? I tried switching the mail set to the bottom to see
if it rendered more quickly and found no change. Hmmm...

Corrected code: --snip--$mailheaders = "From: company name here\n";
$mailheaders = "CC: {$_POST['cpemail']}";
As Tom had pointed out, the missing concat dot was my main
original problem.
PHP does not register array values when placed in double-quoted strings.
In order for this to work they require bracketing with {} or escaping from
the string altogether.


That did it, thanks.

One question wasn't answered: Should I even be using sessions
to pass data from one page to another for both display and
email? Or will the post data be valid there? I'm still not
clear on scope.

I picked up Rasmus Lerdorf's "Programming PHP" book but haven't
had a chance to go cover-to-cover on it yet. It should help
bring me back up to speed a few weeks from now.

Jul 17 '05 #6
On Tue, 07 Oct 2003 15:59:38 GMT, "Tom Thackrey"
<us***********@nospam.com> wrote:

On 7-Oct-2003, Phil Roberts <ph*****@HOLYflatnetSHIT.net> wrote:
With total disregard for any kind of safety measures "Tom
Thackrey" <us***********@nospam.com> leapt forth and uttered:
> The script you posted compiles without syntax errors. It does
> have a problem in that the array subscripts inside a double
> quoted string should not have single quotes around them. That is
> it should be "\t$_POST[cpcomp]\n".


Incorrect, all array keys should be quoted unless you're passing
a constant. If PHP sees an unquoted array key it has to check to
make sure it isn't a constant before processing it and will
throw a Notice error.


Not true. Array references inside double quotes behave differently. Inside
double quotes $a[b] is the same as {$a['b']} and constant lookup is not
done.

From the doc:
// Works but note that this works differently outside string-quotes
echo "A banana is $fruits[banana].";
// Works
echo "A banana is {$fruits['banana']}.";
// Works but PHP looks for a constant named banana first
// as described below.
echo "A banana is {$fruits[banana]}.";
// Won't work, use braces. This results in a parse error.
echo "A banana is $fruits['banana'].";
http://www.php.net/manual/en/languag...parsing.simple


Well, it may be simple parsing to you, but I just catenate the value
with the string, and it all works fine every time (:

eg

echo 'A banana is ' . $fruits['banana'] . '.';

I also use single quotes because of the huge number of double quotes
that you need to use when generating html suddenly don't need escaping
to appear.

$0.02

Steve
(I blame old age, unix and whisky, but not necessarily in that order)

Jul 17 '05 #7

On 7-Oct-2003, Steve Holdoway <st***@itemfront.ltd.uk> wrote:
Well, it may be simple parsing to you, but I just catenate the value
with the string, and it all works fine every time (:

eg

echo 'A banana is ' . $fruits['banana'] . '.';

I also use single quotes because of the huge number of double quotes
that you need to use when generating html suddenly don't need escaping
to appear.

$0.02


<sarcasm>
Oh now I see the light!

echo 'A banana is '.$fruits['banana'].'.';
is so much simpler, easier to read, and uses less "s than
echo 'A banana is $fruits[banana].';
too bad Dijkstra's dead he could revolutionize programming with a new paper
"Double Quotes considered harmful."
</sarcasm>

Go with whatever works for you.

--
Tom Thackrey
www.creative-light.com
tom (at) creative (dash) light (dot) com
do NOT send email to ja*********@willglen.net (it's reserved for spammers)
Jul 17 '05 #8
Following up on my own post...

On Tue, 07 Oct 2003 16:10:26 GMT, Larry Jaques <jake@di\/ersify.com>
pixelated:
On Tue, 07 Oct 2003 04:10:35 -0500, Phil Roberts
<ph*****@HOLYflatnetSHIT.net> pixelated:
With total disregard for any kind of safety measures "Tom
Thackrey" <us***********@nospam.com> leapt forth and uttered:
The script you posted compiles without syntax errors. It does
have a problem in that the array subscripts inside a double
quoted string should not have single quotes around them. That is
it should be "\t$_POST[cpcomp]\n".


Incorrect, all array keys should be quoted unless you're passing
a constant. If PHP sees an unquoted array key it has to check to
make sure it isn't a constant before processing it and will
throw a Notice error.


Taking both sets of advice, I came up with:

<td align=left><font face="tahoma,arial" size="-1"><? echo
"{stripslashes($_POST['cpcity'])} , {$_POST['cpstate']}
{$_POST['cpzip']}" ?></td></tr> (browser wrap)

This didn't work until I removed the quotes from 'cpcity'.
This now displays: "City: {stripslashes(Cityfield)} , ST 45678"
where the input was "Cityfield", "ST", and "45678".
When I removed the curly braces from city, it gave the
same output (sans curly braces.)

The double quotes allowed me to place the comma.

This page is taking between 12 and 15 seconds to render, too.
Is echoing the entire script quicker than individual calls
to PHP? I tried switching the mail set to the bottom to see
if it rendered more quickly and found no change. Hmmm...


I ended up with this: <td align=left><font face="tahoma,arial"
size="-1"><? echo stripslashes($_POST['cpcity']) ?>, <? echo
$_POST['cpstate'] ?> &nbsp;<? echo $_POST['cpzip'] ?></td></tr>
Corrected code:

--snip--
$mailheaders = "From: company name here\n";
$mailheaders = "CC: {$_POST['cpemail']}";


As Tom had pointed out, the missing concat dot was my main
original problem.
PHP does not register array values when placed in double-quoted strings.
In order for this to work they require bracketing with {} or escaping from
the string altogether.


That did it, thanks.


Well, it did it for echoing to the page. Now I have email with

{stripslashes(John L\'Esp)}, {stripslashes(CEO)} showing
since Magic Quotes are turned on on that server, which
steered me to prior processing:

<?
$cpn = stripslashes($_POST[cpname]);
etc. then post to the mail message.

Got it!
Now how do I maintain the form data during validation if
they miss an entry? The back button provides a blank form
again.

Jul 17 '05 #9
I noticed that Message-ID:
<et*******************@newssvr25.news.prodigy.co m> from Tom Thackrey
contained the following:
<sarcasm>
Oh now I see the light!

echo 'A banana is '.$fruits['banana'].'.';
is so much simpler, easier to read, and uses less "s than
echo 'A banana is $fruits[banana].';
too bad Dijkstra's dead he could revolutionize programming with a new paper
"Double Quotes considered harmful."
</sarcasm>

Go with whatever works for you.


printf("a banana is a %s",$fruits['banana']);

;-)

--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #10
I noticed that Message-ID: <aa********************************@4ax.com>
from Larry Jaques <jake@di\/ersify.com> contained the following:
Now how do I maintain the form data during validation if
they miss an entry? The back button provides a blank form
again.


I do something like this

<input type="text" name="firstname" size="35" maxlength="30"
value="<?php echo $_POST['firstname'] ;?>">
--
Geoff Berrow
It's only Usenet, no one dies.
My opinions, not the committee's, mine.
Simple RFDs http://www.ckdog.co.uk/rfdmaker/
Jul 17 '05 #11
On Wed, 08 Oct 2003 00:10:59 +0100, Geoff Berrow
<bl@ckdog.co.uk.the.cat> pixelated:
I noticed that Message-ID: <aa********************************@4ax.com>
from Larry Jaques <jake@di\/ersify.com> contained the following:
Now how do I maintain the form data during validation if
they miss an entry? The back button provides a blank form
again.


I do something like this

<input type="text" name="firstname" size="35" maxlength="30"
value="<?php echo $_POST['firstname'] ;?>">


Thanks, I'll try that first thing tomorrow morning, once my
eyes are uncrossed. How are you validating entry data/catching
blank fields? All my previous experience is with accessing
previous data, not new, raw data coming in, so I'm in a whole
new field with this one.

I found a script/tutorial on Evolt which has me in knots. I'm
not quite sure how to make the script move on once the missing
info is entered...if I can find all my typos first. ;)
http://evolt.org/article/User_Friend...n_PHP/20/60144

Jul 17 '05 #12

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by zhimin | last post: by
1 post views Thread by michi | last post: by
6 posts views Thread by scottyman | last post: by
11 posts views Thread by cybervigilante | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by haryvincent176 | last post: by
reply views Thread by Marylou17 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.