php-general Digest 3 Mar 2013 00:28:08 -0000 Issue 8145
Topics (messages 320355 through 320366):
Re: Joining fixed text to a SUBJECT variable
320355 by: Jim Giner
320362 by: tamouse mailing lists
320363 by: tamouse mailing lists
320364 by: Michael CALDER
320365 by: Jim Lucas
Re: Introduction ... !
320356 by: Jay Blanchard
320357 by: Matt Giddings
320358 by: Jay Blanchard
320359 by: Stuart Dallas
320360 by: Jay Blanchard
320361 by: tamouse mailing lists
320366 by: Tedd Sperling
Administrivia:
To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net
To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net
To post to the list, e-mail:
php-gene...@lists.php.net
----------------------------------------------------------------------
--- Begin Message ---
On 3/2/2013 7:03 AM, Maciek Sokolewicz wrote:
The problem is the simple fact that the variable $MessageSubject is not
defined until 4 lines farther into the script. Changing the variable to
$_POST['MessageSubject'] (and concatenating using the concatenation
operator (the period: '.' )) should fix this for you.
If Michael had E_NOTICE errors turned on, he would see an E_NOTICE:
"Undefined variable" on line 6. Apparently, he doesn't show E_NOTICEs
either.
Exactly.
--- End Message ---
--- Begin Message ---
On Sat, Mar 2, 2013 at 5:04 AM, Michael CALDER
<mikecal...@optusnet.com.au> wrote:
>
> -- G'day ,
G'day, cobber!
> Here is the current contact2.php file - but the SUBJECT only shows as
> RVRA Contact Form -
Others have addressed that, as well as not needing the stripslashes.
If you will permit, I have a few other comments. If not, simply
delete. No worries!
I added line numbers to make notation easier.
1 > <?php
2 >
3 > // get posted data into local variables
4 > $EmailAddress = Trim(stripslashes($_POST['EmailAddress']));
5 > $EmailTo = "mikecal...@optusnet.com.au";
You might want to use a configured value instead of the direct string.
If you have to change the email address, or other similar things, it's
easier to change a configuration file than looking through code.
6 > $Subject = "RVRA Contact Form - ,$MessageSubject";
Similarly here, the subject of the email could be a configured item.
7 > $Name = Trim(stripslashes($_POST['Name']));
8 > $EmailAddress = Trim(stripslashes($_POST['EmailAddress']));
You've duplicated this from line 4.
9 > $YesNo = Trim(stripslashes($_POST['YesNo']));
10 >
11 > $MessageSubject = Trim(stripslashes($_POST['MessageSubject']));
12 > $Message = Trim(stripslashes($_POST['Message']));
13 >
14 > // send email
15 > if(!isset($_REQUEST['identiPIC_selected'])){exit;}
Instead of just throwing an exit here, and giving the user a blank
page, maybe better to redirect to some landing page. This is done by
issuing a header before any other text is sent:
header("Location: your-error-landing-page.html");
16 >
17 > $identiPIC[1] = "Bird";
18 > $identiPIC[2] = "Logo";
19 > $identiPIC[3] = "Flower";
20 >
21 > if($_REQUEST['identiPIC_selected'] !== $identiPIC){print "<meta
22 > http-equiv=\"refresh\" content=\"0;URL=error-pic.html\">"; exit;}
Here, instead of making the browser refresh, do a redirect to a landing page.
See above for header.
23 >
24 >
25 >
26 >
27 > // prepare email body text
28 > $Body = "";
29 >
30 > $Body .= "Name: ";
31 > $Body .= $Name;
32 > $Body .= "\n";
33 >
34 > $Body .= "EmailAddress: ";
35 > $Body .= $EmailAddress;
36 > $Body .= "\n";
37 >
38 > $Body .= "RVRA Member";
39 > $Body .= $YesNo;
40 > $Body .= "\n";
41 >
42 >
43 >
44 > $Body .= "Message Subject: ";
45 > $Body .= $MessageSubject;
46 > $Body .= "\n";
47 >
48 > $Body .= "Message: ";
49 > $Body .= $Message;
50 > $Body .= "\n";
This is the ideal place for a HEREDOC
(http://www.php.net/manual/en/language.types.string.php#language.types.string.syntax.heredoc)
to make your code more readable and maintainable:
$Body <<ENDOFMAIL
Name: $Name
EmailAddress: $EmailAddress
RVRA Member: $YesNo
Message Subject: $MessageSubject
$Message
ENDOFMAIL
51 >
52 >
53 > // send email
54 > $success = mail($EmailTo, $Subject, $Body, "From: <$EmailAddress>");
The fourth parameter is actually any additional headers, and should be
constructed in the standard mail format, the header name, the proper
contents and terminated by a CR-LF.
In this case, the From: header needs to correspond to an RFC2922
address, or list of such addresses. If you want to use the angle
brackets, you need to put in a user name before it. Otherwise, simply
omit the brackets. All the additional headers specified in the fourth
parameter need to end with a CR-LF as well, not just a LF, or in this
case, nothing. The way this is set up, the following would be proper
setup:
$AdditionalParms = "From: \"$Name\" <$EmailAddress>\r\n";
Then:
$success = mail ($EmailTo, $Subject, $Body, $AdditionalParms);
The escaped quotes around $Name allow for such things as
non-alnum+space characters, i.e., something like this would be
allowed:
From: "Samuel L. Jackson, Jr." <sammyj...@example.com>
However, in this case, the email is NOT actually being sent from
$EmailAddress, it is being sent from your server, so putting in that
address is technically a spoof. While that's not illegal, some mailing
systems will call that a spam message, as the From and Sender do not
match, and From won't be found at the originating mail node.
55 >
56 > // redirect to success page
57 > if ($success){
58 > print "<meta http-equiv=\"refresh\"
content=\"0;URL=thanks.html\">";
59 > }
60 > else{
61 > print "<meta http-equiv=\"refresh\"
content=\"0;URL=error-pic.html\">";
62 > }
63 >
Here again, give the idea of using a header redirect instead of a
browser refresh a go.
64 > ?>
--- End Message ---
--- Begin Message ---
Ah, crikey, syntax error!!
> $Body <<ENDOFMAIL
should be:
$Body = <<ENDOFMAIL
assignment operator necessary!!
--- End Message ---
--- Begin Message ---
G'day ,
Thanks to you both I have muddled through. The actual answer was
$Subject = "RVRA Contact Form - ".$_POST['MessageSubject'];
I had tried something like that but I used a comma instead of the period.
And, yes, I was getting error messages "Undefined variable" on line 6.
etc but was too dumb to work out the fix :-(
The other bloke talking strine on 'tamouse' has given me plenty to work
on. I see you were also talking about spring chickens and autumn
turkeys. I reckon I am almost a dodo at 82 :-)
Thanks again to you all.
Cheers....
Mike
Michael CALDER
73/81 Willandra Road,
CROMER NSW 2099
02 9981 6327
On 02/03/13 23:03, Maciek Sokolewicz wrote:
On 2-3-2013 12:23, Lester Caine wrote:
Michael CALDER wrote:
$Subject = "RVRA Contact Form - ,$MessageSubject";
Can anyone please advise or point me in the right direction for
instructions on how to combine the fixed text with the variable
$MessageSubject.
The quick fix is simply
$Subject = "RVRA Contact Form - ".$MessageSubject;
but
$Subject = "RVRA Contact Form - ,$MessageSubject";
should work, what is the error? ... you don't actually want the ','
$Subject = "RVRA Contact Form - $MessageSubject";
Should work as well
No it shouldn't, unless you have register_globals turned On. Which most
hosts don't (and shouldn't) do.
The problem is the simple fact that the variable $MessageSubject is not
defined until 4 lines farther into the script. Changing the variable to
$_POST['MessageSubject'] (and concatenating using the concatenation
operator (the period: '.' )) should fix this for you.
If Michael had E_NOTICE errors turned on, he would see an E_NOTICE:
"Undefined variable" on line 6. Apparently, he doesn't show E_NOTICEs
either.
--- End Message ---
--- Begin Message ---
On 3/2/2013 11:56 AM, tamouse mailing lists wrote:
Ah, crikey, syntax error!!
$Body <<ENDOFMAIL
should be:
$Body = <<ENDOFMAIL
assignment operator necessary!!
AND... it should have 3 <<< instead of 2 <<
http://www.php.net/manual/en/language.types.string.php \
#language.types.string.syntax.heredoc
--
Jim Lucas
--- End Message ---
--- Begin Message ---
[snip]
...good conversation...
[/snip]
I have been on this list for years and I have watched it ebb and flow. I
have heard all the bad and good about PHP. The fact remains that we use
PHP in some very heavy applications and it never fails us for what we
want or need to do. I always encourage devs to use the proper tool for
the job, and when using that tool use it to its maximum capability. Let
each tool do the heavy lifting that it is designed to do. PHP can tote
some really heavy loads when asked properly.
--- End Message ---
--- Begin Message ---
I've been on this list since the early 2000's. I used to participate a lot
back then but then took up a non-php related job and I stopped paying
attention to the list. I've been working again with php for the past 4.5
years but choose to just monitor the list and haven't participated much.
Perhaps I should participate more. But yeah, I've been here like 12 years
or so. God I'm getting old.
On Sat, Mar 2, 2013 at 11:10 AM, Jay Blanchard <
jay.blanch...@sigmaphinothing.org> wrote:
> [snip]
> ...good conversation...
> [/snip]
>
> I have been on this list for years and I have watched it ebb and flow. I
> have heard all the bad and good about PHP. The fact remains that we use PHP
> in some very heavy applications and it never fails us for what we want or
> need to do. I always encourage devs to use the proper tool for the job, and
> when using that tool use it to its maximum capability. Let each tool do the
> heavy lifting that it is designed to do. PHP can tote some really heavy
> loads when asked properly.
>
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
[snip]
I've been on this list since the early 2000's. I used to participate a lot
back then but then took up a non-php related job and I stopped paying
attention to the list. I've been working again with php for the past 4.5
years but choose to just monitor the list and haven't participated much.
Perhaps I should participate more. But yeah, I've been here like 12 years
or so. God I'm getting old.
[/snip]
No - Tedd is old. The rest of us are just Spring chickens.
--- End Message ---
--- Begin Message ---
On 2 Mar 2013, at 16:25, Jay Blanchard <jay.blanch...@sigmaphinothing.org>
wrote:
>> [snip]
>> I've been on this list since the early 2000's. I used to participate a lot
>> back then but then took up a non-php related job and I stopped paying
>> attention to the list. I've been working again with php for the past 4.5
>> years but choose to just monitor the list and haven't participated much.
>> Perhaps I should participate more. But yeah, I've been here like 12 years
>> or so. God I'm getting old.
>> [/snip]
> No - Tedd is old. The rest of us are just Spring chickens.
Speak for yourself, I'm an autumn turkey!
-Stuart
--
Stuart Dallas
3ft9 Ltd
http://3ft9.com/
--- End Message ---
--- Begin Message ---
[snip]
Speak for yourself, I'm an autumn turkey! -Stuart
[/snip]
My body is an Autumn turkey, my head says differently - save on certain
mornings when too much popping and cracking occurs.
--- End Message ---
--- Begin Message ---
On Sat, Mar 2, 2013 at 10:35 AM, Jay Blanchard
<jay.blanch...@sigmaphinothing.org> wrote:
> [snip]
>
> Speak for yourself, I'm an autumn turkey! -Stuart
> [/snip]
>
> My body is an Autumn turkey, my head says differently - save on certain
> mornings when too much popping and cracking occurs.
See, you can't really call yourself old until that's pooping and cramping...
--- End Message ---
--- Begin Message ---
On Mar 2, 2013, at 11:25 AM, Jay Blanchard <jay.blanch...@sigmaphinothing.org>
wrote:
>> No - Tedd is old. The rest of us are just Spring chickens.
Hey, let's watch that... ahhhh, what? What the hell was I saying???
Awww .. forget it.
Did I tell you about when I programed with rocks? That was before someone
invented the absence of rock (a really abstract idea) and then things got mondo
weird. We were finally able to build things that didn't always look like
pyramids. You see, we had been stuck in Oh Oh Pyramids days, which we called
OOP.
The more things change...
Cheers,
tedd
_____________________
t...@sperling.com
http://sperling.com
--- End Message ---