473,390 Members | 1,273 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,390 software developers and data experts.

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 3458

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

21
by: MLH | last post by:
A97 procedure to open http://www.arch.com/message/ enter an 800 number, press "Continue", enter a text msg string from a memo field and press "Send" This is a calendaring and appointment A97...
0
by: zhimin | last post by:
Hi, I'm writing a program to send large file(100m) through dotnet using TCPListener & TCPClient, I'm sending the file with a ask and response loop: 1. Client send a flag 1 to server indicate it...
1
by: michi | last post by:
Hi there.... Got here a tricky thing with my SMTP. First I show you what works on my machine.. **This Works** SmtpMail.SmtpServer = "mail.gmx.net" <-gmx is my mail provider...
1
by: Miguel Dias Moura | last post by:
Hello, Can you help me out in making this work? What I want is as simple as sending form values to an email. The code I am using is the following:
4
by: Aren Cambre | last post by:
Why does SmtpMail.Send throw an exception if the MailMessage's BodyFormat = MailFormat.Html? I've searched all over the place and cannot find a solution anywhere. I am running this on Windows XP...
3
by: Gerard | last post by:
Hello I have created a windows service to monitor a database, it starts some checks when a timer elapses. The checks send emails depending on their findings. My issue is that when I created a...
1
by: Phill. W | last post by:
Have Our Friends in Redmond put delay loops into the SMTPMail.Send() method, or does it /really/ take almost a second to send a mail message? I've written a windows service that send emails. ...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
3
by: BuddyWork | last post by:
Hello, Could someone please explain why the Socket.Send is slow to send to the same process it sending from. Eg. Process1 calls Socket.Send which sends to the same IP address and port, the...
11
by: cybervigilante | last post by:
I can't seem to change the include path on my local winmachine no matter what I do. It comes up as includ_path .;C:\php5\pear in phpinfo() but there is no such file. I installed the WAMP package...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.