Jump to content

[SOLVED] Mail error


slpctrl

Recommended Posts

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

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

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

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 :P. 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++ :P.

 

 

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 :P But I guess some people need more structure like that..again I'm used to a compiled programming structure. My mistakes :P

Link to comment
https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636929
Share on other sites

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');
}
?>

 

:P

Link to comment
https://forums.phpfreaks.com/topic/123317-solved-mail-error/#findComment-636936
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.