Re: [PHP] Joining fixed text to a SUBJECT variable

2013-03-02 Thread Jim Lucas

On 3/2/2013 11:56 AM, tamouse mailing lists wrote:

Ah, crikey, syntax error!!



$Body <

should be:

$Body = <

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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Joining fixed text to a SUBJECT variable

2013-03-02 Thread Michael CALDER



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.



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Joining fixed text to a SUBJECT variable

2013-03-02 Thread tamouse mailing lists
On Sat, Mar 2, 2013 at 5:04 AM, Michael CALDER
 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  > 
 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 " 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 <
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." 


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 "";
59  > }
60  > else{
61  > print "";
62  > }
63  >

Here again, give the idea of using a header redirect instead of a
browser refresh a go.


64  > ?>

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Joining fixed text to a SUBJECT variable

2013-03-02 Thread Jim Giner

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.

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Joining fixed text to a SUBJECT variable

2013-03-02 Thread Maciek Sokolewicz

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.


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Joining fixed text to a SUBJECT variable

2013-03-02 Thread Lester Caine

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

--
Lester Caine - G8HFL
-
Contact - http://lsces.co.uk/wiki/?page=contact
L.S.Caine Electronic Services - http://lsces.co.uk
EnquirySolve - http://enquirysolve.com/
Model Engineers Digital Workshop - http://medw.co.uk
Rainbow Digital Media - http://rainbowdigitalmedia.co.uk

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php