/    Sign up×
Community /Pin to ProfileBookmark

Modifications, and clarification please!

Hello.
I hope you can help me please.
I have a few questions about my mailer below which I hope you can help me on.

The questions are beneath the code:

[code=php]
removed to save your b/width! resolved. πŸ™‚
[/code]

Question 1.
For the subject of the mail I currently have:

[code=php]$subject = ‘Ticket [ID:’ . $id .’]’;[/code]

Should this be:

[code=php]$subject = “Ticket [ID:” . $id .”]”;[/code]

?
I was unsure of single or double quotes for this.

Question 2.

Is there a way to look for certain words in the submission from the form, and replace them with something? I.e. if someone wrote ‘tree’ is there a way to put this as ‘dog’ .. this is just an example of course, we are looking to replace denied words.

Question 3.

Is my use of strip_tags and the nl2br ok on the “copy” of the submission on the last echo? It all works, but I don’t know if it’s right!

Question 4.

If you can spot anything that’s wrong, or you’d do differently please let me know! If you see any security issues please let me know also!

Many many thanks in advance!

to post a comment
PHP

29 Comments(s) ↴

Copy linkTweet thisAlerts:
@scragarDec 13.2004 β€”Β 1:
[code=php]$subject = 'Ticket [ID:' . $id .']';[/code]
is, to all intensive purposes, the same as
[code=php]$subject = "Ticket [ID:" . $id ."]";[/code]
the only thing you could actualy do to change this would be:
[code=php]$subject = "Ticket [ID:$id]";[/code]
although this still has the same output.

2:

before [code=php]mail($to, $subject, $msg, $headers);[/code]
add: [code=php]$msg = str_replace("nasty","nice word",$msg);
$msg = str_replace("another nasty word","its a nice word",$msg);
$msg = str_replace("evil word","good word",$msg);[/code]


3:

yes, nl2br(strip_tags("txt")); is the correct santax as you wrote.

4:

that should be fine.
Copy linkTweet thisAlerts:
@DanUKauthorDec 13.2004 β€”Β Ok brilliant. Thank you ever so much!

One more question I forgot, sorry!

[code=php]$msg .= "Submitted from IP: ".$_SERVER['REMOTE_ADDR']."nn";[/code]

Is there a way to get this to display 222.222.222.222[example.domain.com]

I think it would be gethostbyaddr but how would I incorporate it?

Thanks!
Copy linkTweet thisAlerts:
@scragarDec 13.2004 β€”Β $msg .= "Submitted from IP: ".$_SERVER['REMOTE_ADDR']."nn";


could become:

$msg .= "Submitted from IP: ".$_SERVER['REMOTE_ADDR']."[".gethostbyaddr($_SERVER['REMOTE_ADDR'])."]nn";


EDIT: try this
[code=php]$msg .= "Submitted from IP: ".$_SERVER['REMOTE_ADDR'];
if(gethostbyaddr($_SERVER['REMOTE_ADDR']) != $_SERVER['REMOTE_ADDR']){
// the user has a website so we write that out in the square brackets.
$msg .= "[".gethostbyaddr($_SERVER['REMOTE_ADDR'])."]";
};
$msg .= "nn";[/code]
Copy linkTweet thisAlerts:
@DanUKauthorDec 13.2004 β€”Β Hi again!

Thank you for your speedy response.

I appreciate your help ?

What do you mean by "unless the user has a website"? I didn't understand this...

So if I was to use the following, if the IP had a Reverse DNS that would be shown, otherwise it'd just show:

[code=php]222.222.222.222[][/code]

and if it had reverse:

[code=php]222.222.222.222[something.domain.com][/code]

right? ?
Copy linkTweet thisAlerts:
@scragarDec 13.2004 β€”Β I edited my post, sorry.

[code=php]$msg .= "Submitted from IP: ".$_SERVER['REMOTE_ADDR'];
if(gethostbyaddr($_SERVER['REMOTE_ADDR']) != $_SERVER['REMOTE_ADDR']){
// the user has a website so we write that out in the square brackets.
$msg .= "[".gethostbyaddr($_SERVER['REMOTE_ADDR'])."]";
};
$msg .= "nn";[/code]


will work.

what actualy happens is that if the user doesn't have a website it would write out the IP adress, a quick check against this then allows for it to only appear where the user has a website.
Copy linkTweet thisAlerts:
@DanUKauthorDec 13.2004 β€”Β Super thanks! That is working perfectly!

I assume by "website" you mean Reverse DNS right, as that's why gethostbyaddr is looking for (internet host for an IP)

Also one last question. The code for replacing those "bad words" is working perfectly.

However it seems it's case sensitive.

So let's say my line is:
[code=php]$msg = str_replace("tree","wood",$msg);[/code]

if "tree" is in the submission, it's correctly replaced to wood.

However, is it's spelt like Tree, TrEe, tReE etc, it still gets through.

Is it possible to make it check all cases? ?

Many thanks, I really appreciate it.
Copy linkTweet thisAlerts:
@scragarDec 13.2004 β€”Β erm...


$msg = eregi_replace("from","to",$msg);


this is slower...
Copy linkTweet thisAlerts:
@DanUKauthorDec 13.2004 β€”Β Ohh I see...

But although it's slower, it won't matter about the case, it's still replace it? If so..that's what we'll have to use. ?

Many thanks again.

Also, I'd like to throw in one more question and promise it's my last! (sorry!!!)

[code=php]
if (!isset($_SESSION['correctcode'])) {
die("Please enable cookies");
}
[/code]


Looking at the mailer, would you say I need this? I wouldn't think so because it's on sessions?

Thanks!
Copy linkTweet thisAlerts:
@scragarDec 13.2004 β€”Β that checks that is used to hold the number for later(when you compare it) if you deleted that then you'd get an error later on when you atempted to run the number comparison.
Copy linkTweet thisAlerts:
@DanUKauthorDec 13.2004 β€”Β Okay then, thanks. ?

Back to the replacing the bad works, I saw on http://it.php.net/str_ireplace

"str_ireplace -- Case-insensitive version of str_replace()."

Would this be ok to use?

so ..

[code=php]$msg = str_ireplace("tree","wood",$msg);[/code]
Copy linkTweet thisAlerts:
@scragarDec 13.2004 β€”Β yeah, I used the long winded one because I was planning on writing them all into a single expression(which would be quicker to run and modify, but harder to understand).

$msg = eregi_replace(/(Bad1|Bad2|Bad3)/,"*a bad word went here*",$msg);

would proberly run faster if you had more than 20 words to replace, but you couldn't do individual comments for each one (so each word would not have a unique replacment like tree becomes wood and bat makes bird this would just replace them all with *A bad word went here*)
Copy linkTweet thisAlerts:
@DanUKauthorDec 13.2004 β€”Β Ah I see.

Yea we'd need it to replace it to something unique, so would you advise to use that:

[code=php]$msg = str_ireplace("tree","wood",$msg);[/code]

There's not going to be many of them, probably about 7.

This is great, quick replier! ?

Many many thanks, I really appreciate this help!
Copy linkTweet thisAlerts:
@scragarDec 13.2004 β€”Β your welcome.
Copy linkTweet thisAlerts:
@DanUKauthorDec 13.2004 β€”Β Last post before I drive you mad! hehehe.

So the ireplace is ok? To use in the way I posted in the last one?

????
Copy linkTweet thisAlerts:
@scragarDec 13.2004 β€”Β its fine.

arn't you doing any kind of test on this? if so they you should just check it, it'll work fine.
Copy linkTweet thisAlerts:
@DanUKauthorDec 13.2004 β€”Β Yeah I should...but it's on a production server that gets approximately 10 submissions every 5 mins, so I just wanted to confirm unless I understood something wrong and borked it up!

I should set up something at home to test it locally.

You've answered all my queries, thank you EVER so much, you've been a great help!
Copy linkTweet thisAlerts:
@scragarDec 13.2004 β€”Β I have my localhost stored on a pen drive so regardless of where I am I can always check it on a nearby computer or (if nessesary, I don't like to waste the battery power though..) my laptop without having to access a webhost or something like that.
Copy linkTweet thisAlerts:
@DanUKauthorDec 13.2004 β€”Β ooo problem!

[code=php]Fatal error: Call to undefined function: str_ireplace() in /home/me/support-mailer.php on line 87[/code]

Line 87 is the first str_ireplace:

[code=php]$msg = str_ireplace("tree","wood",$msg);[/code]

?
Copy linkTweet thisAlerts:
@NogDogDec 13.2004 β€”Β What version of PHP are you using? [font=courier new]str_ireplace()[/font] is only available as of PHP 5.
Copy linkTweet thisAlerts:
@DanUKauthorDec 13.2004 β€”Β Thanks for your reply.

Ah. ?

PHP Version 4.3.2

That seemed perfect because it didn't matter about case. Anything else I can use which will not matter about case etc? ?
Copy linkTweet thisAlerts:
@scragarDec 13.2004 β€”Β use ereg_replace(/from/i,"to",$msg);
Copy linkTweet thisAlerts:
@NogDogDec 13.2004 β€”Β How about:
[code=php]
$msg = preg_replace("/tree/i","wood",$msg);
[/code]
Copy linkTweet thisAlerts:
@DanUKauthorDec 13.2004 β€”Β Ok thanks. ?

So for ex:

[code=php]
ereg_replace(/tree/i,"wood",$msg);
ereg_replace(/land/i,"sky",$msg);
[/code]


I read php.net/ereg_replace but coulnd't see why the "/"'s have been used and the "i", what do they do?

?
Copy linkTweet thisAlerts:
@NogDogDec 13.2004 β€”Β [i]Originally posted by DanUK [/i]

[B]Ok thanks. ?



So for ex:



[code=php]
ereg_replace(/tree/i,"wood",$msg);
ereg_replace(/land/i,"sky",$msg);
[/code]


I read php.net/ereg_replace but coulnd't see why the "/"'s have been used and the "i", what do they do?

? [/B][/QUOTE]

http://us3.php.net/manual/en/reference.pcre.pattern.modifiers.php
Copy linkTweet thisAlerts:
@scragarDec 13.2004 β€”Β the forward slashes tell it to use a regular expresion and not a string(with quotes) while the i tells it to ignore the case.
Copy linkTweet thisAlerts:
@DanUKauthorDec 13.2004 β€”Β [code=php]
$msg = preg_replace("/tree/i","wood",$msg);
$msg = preg_replace("/land/i","sky",$msg);
$msg = preg_replace("/badword/i","goodword",$msg);
[/code]


is working great! Thanks!!!

When I tried the ereg_replace let's say:

[code=php]$msg = ereg_replace("/land/i","sky",$msg);[/code]

I just got PHP errors.

preg_replace seems to be working great though. ?
Copy linkTweet thisAlerts:
@DanUKauthorDec 14.2004 β€”Β Hi again. ?

Just out of interest, what was it that was stopping ereg_replace from working, as given in my last post?

Apart from this, preg_replace seems to be working good. ?

Thanks.

Regards,
Copy linkTweet thisAlerts:
@scragarDec 14.2004 β€”Β it's the wrong funtion, I'm just stoopid and couldn't find the funtion, ereg_replace is used fo strings when you wanto to convert a string into something else while preserving some information (like for Bulitin board code)
Copy linkTweet thisAlerts:
@DanUKauthorDec 14.2004 β€”Β Ah ok!

Well cool, thank you very very much for your help. ?
Γ—

Success!

Help @DanUK spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 β€” BETA 5.2,
whats_new: community page,
up_next: more Davinciβ€’003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinciβ€’003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...