slpctrl Posted September 8, 2008 Share Posted September 8, 2008 Alright, here's my mail code: <?php function mailcheck($input) { if (eregi(”\r”, $input) || eregi(”\n”, $input) || eregi(”%0a”, $input) || eregi(”%0d”, $input) || eregi(”Content-Type:”, $input) || eregi(”bcc:”, $input) || eregi(”to:”, $input) || eregi(”cc:”, $input)) { return true; } else { return false; } } $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $msg = "Name: $name<br>Email Address: $email<br>Message: $message"; if(!mailcheck($email)) die(); else { mail("[email protected]","Website Inquiry",$msg); header('location: index.htm'); } ?> And the error I'm getting is: Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /home/content/s/t/a/stagecoachoh/html/mail.php on line 3 Parse error: syntax error, unexpected T_STRING in /home/content/s/t/a/stagecoachoh/html/mail.php on line 3 Not sure why I'm getting this, but I grabbed the script (the function declared in there...it's purpose is to prevent bots from using the email form with email injection to spam) from here: http://www.tonyspencer.com/2005/12/15/email-injection-exploit-through-a-php-contact-form/ If that helps. Any help would be greatly appreciated, I can't seem to find why I'm getting this error. Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/ Share on other sites More sharing options...
discomatt Posted September 8, 2008 Share Posted September 8, 2008 Looks like you're using fancy quotes. Are you sure you're using a proper plain text editor? <?php function mailcheck($input) { if (eregi("r", $input) || eregi("n", $input) || eregi("%0a", $input) || eregi("%0d", $input) || eregi("Content-Type:", $input) || eregi("bcc:", $input) || eregi("to:", $input) || eregi("cc:", $input)) { return true; } else { return false; } } $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $msg = "Name: $name<br>Email Address: $email<br>Message: $message"; if(!mailcheck($email) || !mailcheck($email)) die(); else { mail("[email protected]","Website Inquiry",$msg); header('location: index.htm'); } ?> Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636891 Share on other sites More sharing options...
BlueSkyIS Posted September 8, 2008 Share Posted September 8, 2008 right-o: it's probably those weird double-quotes you're using. what's up with that? Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636892 Share on other sites More sharing options...
DarkWater Posted September 8, 2008 Share Posted September 8, 2008 Yeah, and why are you using mailcheck() twice on $email? Shouldn't you be using it on $message? Also, <br> won't work unless you have HTML headers. Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636893 Share on other sites More sharing options...
slpctrl Posted September 8, 2008 Author Share Posted September 8, 2008 Yeah, and why are you using mailcheck() twice on $email? Shouldn't you be using it on $message? Also, <br> won't work unless you have HTML headers. I edited that. And those weird quotes must have come from where I grabbed the script from. But now when I execute my script it goes to a blank page and doesn't send the email . Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636899 Share on other sites More sharing options...
DarkWater Posted September 8, 2008 Share Posted September 8, 2008 Add: <?php ini_set('display_errors', 1); error_reporting(E_ALL); ?> To the top of your page. Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636902 Share on other sites More sharing options...
slpctrl Posted September 8, 2008 Author Share Posted September 8, 2008 Add: <?php ini_set('display_errors', 1); error_reporting(E_ALL); ?> To the top of your page. It didn't provide any errors . I'd hate to just have to put the form up there unprotected, but this is for a paid job and I have to do something . Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636909 Share on other sites More sharing options...
DarkWater Posted September 8, 2008 Share Posted September 8, 2008 That's a pretty ugly script for a paid job. Why are you doing paid jobs without learning the basics? Anyway, try changing your header() call to 'Location: ' instead of 'location: '. Maybe the browser is being quirky. >_> Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636914 Share on other sites More sharing options...
BlueSkyIS Posted September 8, 2008 Share Posted September 8, 2008 have die tell you something. otherwise, you'll get a blank page. die("mailcheck failed."); Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636917 Share on other sites More sharing options...
DarkWater Posted September 8, 2008 Share Posted September 8, 2008 have die tell you something. otherwise, you'll get a blank page. die("mailcheck failed."); Good point, forgot about that die() because I don't code if without curly braces, so my eye just kind of skipped that one. Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636920 Share on other sites More sharing options...
BlueSkyIS Posted September 8, 2008 Share Posted September 8, 2008 I don't code if without curly braces me neither. i like to always do something or never do something. i always use curly braces. Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636923 Share on other sites More sharing options...
DarkWater Posted September 8, 2008 Share Posted September 8, 2008 I don't code if without curly braces me neither. i like to always do something or never do something. i always use curly braces. Yeah, it makes for unstructured code, which I don't like. >_> Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636925 Share on other sites More sharing options...
slpctrl Posted September 8, 2008 Author Share Posted September 8, 2008 That's a pretty ugly script for a paid job. Why are you doing paid jobs without learning the basics? Anyway, try changing your header() call to 'Location: ' instead of 'location: '. Maybe the browser is being quirky. >_> I used to do LOTS and LOTS of PHP. I have a bachelors degree in computer science . But yeah, I agree my PHP is pretty crappy right now, the past few days I've been retouching up on my PHP skills, and that script was written when I was trying to get back in the basics. I have a great big portfolio of code I've done that I can now barely understand (I've been doing more python and C++ programming in the last year than anything and have done next to no web design/server scripting). Anyways it was a friend that owns a business that needed a quick website so I told him I'd do him one cheap. It shouldn't take me long to get back in the hang of PHP though, it's not even really considered a programming language in the grand scheme of all the others like C++ . have die tell you something. otherwise, you'll get a blank page. die("mailcheck failed."); Good point, forgot about that die() because I don't code if without curly braces, so my eye just kind of skipped that one. It's unneeded if there's only one line after the if But I guess some people need more structure like that..again I'm used to a compiled programming structure. My mistakes Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636929 Share on other sites More sharing options...
slpctrl Posted September 8, 2008 Author Share Posted September 8, 2008 Alright, it appears that the function must constantly be returning false for some reason, in die() I put die("Email couldn't be sent"); and that's what it echoed. Hmm I don't know ??? Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636932 Share on other sites More sharing options...
slpctrl Posted September 8, 2008 Author Share Posted September 8, 2008 I fixed it. Instead of mailchecking email, which I shouldn't have done, I had to mailcheck the $msg variable. <?php function mailcheck($input) { if (eregi("r", $input) || eregi("n", $input) || eregi("%0a", $input) || eregi("%0d", $input) || eregi("Content-Type:", $input) || eregi("bcc:", $input) || eregi("to:", $input) || eregi("cc:", $input)) { return true; } else { return false; } } $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $msg = "Name: $name<br>Email Address: $email<br>Message: $message"; if(!mailcheck($msg)) die("Email couldn't be sent"); else { mail("[email protected]","Website Inquiry",$msg); header('location: index.htm'); } ?> Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636936 Share on other sites More sharing options...
DarkWater Posted September 8, 2008 Share Posted September 8, 2008 I program in C, C++, Java, and C# (sadly. I just learned it since it's pretty similar to Java). I still use { } around my ifs in those languages as well. And I could have a computer science degree too if I was old enough for college. =P Link to comment https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636948 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.