Forum Moderators: coopster

Message Too Old, No Replies

php email script

unexpected problems

         

webtress

6:36 am on Oct 6, 2005 (gmt 0)

10+ Year Member



I Needed to convert a asp snippet to php :( and this is the last hurdle to jump. Now I know you php gurus would know what to do to get this form to send the email but I rarely touch php code, to be honest I run from it like the plague. So if someone can help me out with this I sure would appreciate it. I receive the following error Parse error: parse error, unexpected '@' - with the code below.

$headers = str_replace('%replyto%', $you@yoursite.com,$headers);

If I try to use single or double quotes around the email address then I get an unexpected T thingy.

One more question, I have been reading about the email injection issues with php would showing the email address in the form expose the form to that problem?

adb64

6:54 am on Oct 6, 2005 (gmt 0)

10+ Year Member



Change

$headers = str_replace('%replyto%', $you@yoursite.com,$headers);

into

$headers = str_replace('%replyto%', $you.'@yoursite.com',$headers);

Regards,
Arjan

webtress

7:02 am on Oct 6, 2005 (gmt 0)

10+ Year Member



adb64 thanks but no joy yet now I get Parse error: parse error, unexpected '.', expecting T_VARIABLE or '$'

coopster

1:26 pm on Oct 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



The suggested syntax looks fine at first glance and should not be producing that error. However, what do you have in that $you variable? That may be causing your issue. Also, make sure the error message you are receiving pertains to the line we are looking at here...

webtress

2:35 pm on Oct 6, 2005 (gmt 0)

10+ Year Member



Well your right looking at the line number it seems there is more tweaking of the script that I need to address. I will post if I can't sort this out thank you for your help.

webtress

7:23 pm on Oct 6, 2005 (gmt 0)

10+ Year Member



It turns out that the $ was causing the problem and the following seems to be working.

$headers = str_replace('%replyto%','you@yourdomain.com',$headers);

jatar_k

10:21 pm on Oct 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think that is because you can't concatenate inside str_replace

if you want to build a var do it in 2 steps

$repvar = $you.'@yoursite.com';
$headers = str_replace('%replyto%', $repvar,$headers);

jatar_k

5:18 pm on Oct 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



well coopster and I talked about this a bit and he actually tested whether concatenation works within the str_replace function

and lo' and behold he's right again (he searches for my mistakes ;))

str_replace('%replyto%', $you.'@yoursite.com',$headers)

that works perfectly, syntax is right and all. So something else must be bumping out your line, maybe a syntax error in the line above?

Though, I often step things out for clarity and if I can't get something to work in it's original form I go from a different angle. There are a few functions that get messed up if you try to concat inside the call. There is also the question of whether you should or not as you may need the data again.

coopster

5:26 pm on Oct 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member




he searches for my mistakes

Now anybody that hangs in this forum knows darn well that is just not true,
we just keep each other in check around here and humiliation builds character. I have a lot of character and I just want everyone to know that jatar_k does too ;)

I remembered testing this in a little snippet before I posted and received no syntax errors, so I thought I would offer a very respectable clarification in that the concatenation would work just fine.

$headers = 'My Name<%replyto%>'; 
$you = 'yourname';
$headers = str_replace('%replyto%', $you.'@yoursite.com',$headers);
print $headers;
exit;

jatar_k

5:28 pm on Oct 10, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I have a lot of character and I just want everyone to know that jatar_k does too

roflmao

too true