FrumpyJones Posted May 24, 2009 Share Posted May 24, 2009 Okay. Below is my PHP code for the mailform on my site. I'm getting the e-mail, but the weird thing is the from info. It SHOULD be "firstname lastname - email", but all I'm getting is a "-.email"... you'll see. Example of the problem is below, followed by the code. Thank you in advance for helping a complete noob. FROM: [email protected] Firstname = Test Lastname = Sample phone number = 123-456-7890 cell = 123-456-7890 e-mail = [email protected] message = This is a test message to demonstrate the weird FROM filed I get in my e-mails. <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $phone = $_POST['phone']; $cell = $_POST['cell']; $email = $_POST['email']; $comments = $_POST['comments']; $valNoBot = $_POST['hiddenField']; /*Sending Email*/ if ($valNoBot == "ihateyoubot"){ $to = "[email protected]"; $subject = "New Mail"; $message = "Form1 Information \n\nFirstname = $firstname\r\nLastname = $lastname\r\nphone number = $phone\r\ncell = $cell\r\ne-mail = $email \nmessage = $comments"; $from = "$firstnamename $lastnamename - $email";} else { print "<h3>Go away you stinkin' bot!</h3> \n"; } // end if if(mail($to, $subject, $message, "From: $from")) header("location: contactsuccess.html"); else header("location: contactfailure.html"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/ Share on other sites More sharing options...
trq Posted May 24, 2009 Share Posted May 24, 2009 $from = "$firstnamename $lastnamename - $email";} should be.... $from = "$firstname $lastname - $email";} Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-841078 Share on other sites More sharing options...
FrumpyJones Posted May 24, 2009 Author Share Posted May 24, 2009 $from = "$firstnamename $lastnamename - $email";} should be.... $from = "$firstname $lastname - $email";} Holy crapsticks! Do you have any idea how many times I looked at this code to figure out that problem???? Wow. I feel like a tool. Thanky uo so much! Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-841079 Share on other sites More sharing options...
FrumpyJones Posted May 24, 2009 Author Share Posted May 24, 2009 *sigh* Okay.. still having a problem. Now it's giving me dots between each piece of the field... Example: [email protected] how do I get rid of the dots? Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-841084 Share on other sites More sharing options...
trq Posted May 24, 2009 Share Posted May 24, 2009 Post your current code. Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-841097 Share on other sites More sharing options...
FrumpyJones Posted May 24, 2009 Author Share Posted May 24, 2009 <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $phone = $_POST['phone']; $cell = $_POST['cell']; $email = $_POST['email']; $comments = $_POST['comments']; $valNoBot = $_POST['hiddenField']; /*Sending Email*/ if ($valNoBot == "ihateubot"){ $to = "[email protected]"; $subject = "New Mail"; $message = "Form1 Information \n\nFirstname = $firstname\r\nLastname = $lastname\r\nphone number = $phone\r\ncell = $cell\r\ne-mail = $email \nmessage = $comments"; $from = "$firstname $lastname - $email";} else { print "<h3>Go away you stinkin' bot!</h3> \n"; } // end if if(mail($to, $subject, $message, "From: $from")) header("location: contactsuccess.html"); else header("location: contactfailure.html"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-841099 Share on other sites More sharing options...
FrumpyJones Posted May 25, 2009 Author Share Posted May 25, 2009 :-\ Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-841482 Share on other sites More sharing options...
FrumpyJones Posted May 31, 2009 Author Share Posted May 31, 2009 I could really use some help with this. The code two posts above is the most recent and my emails are coming with periods between the fields. Example below: [email protected] How do I get rid of these periods??? Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-846400 Share on other sites More sharing options...
darkfreaks Posted May 31, 2009 Share Posted May 31, 2009 solution: <?php function clean($text){ $text=trim($text); $text.=strip_tags('allowed tags'$text); $text.=htmlspecialchars($text,ENT_NOQUOTES); $text.=mysql_real_escape_string($text); $text.=filter_var($text,FILTER_SANITIZE_STRING); } $firstname = clean($_POST['firstname']); $lastname = clean($_POST['lastname']); $phone = $_POST['phone']; $cell = clean($_POST['cell']); $email = $_POST['email']; $comments = clean($_POST['comments']); $valNoBot = clean($_POST['hiddenField']); /*Sending Email*/ if ($valNoBot == "ihateubot"){ $to = "[email protected]"; $subject = "New Mail"; $message = "Form1 Information \n\nFirstname = $firstname\r\nLastname = $lastname\r\nphone number = $phone\r\ncell = $cell\r\ne-mail = $email \nmessage = $comments"; $from = "$firstname $lastname-$email";} str_replace('.','',$from);//replacing dots with nothing else { print "<h3>Go away you stinkin' bot!</h3> \n"; } // end if if(mail($to, $subject, $message, "From: $from")) header("location: contactsuccess.html"); else header("location: contactfailure.html"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-846446 Share on other sites More sharing options...
FrumpyJones Posted June 1, 2009 Author Share Posted June 1, 2009 Okay.. I tried that code and got this error: Parse error: syntax error, unexpected T_VARIABLE in /sendmail.php on line 5 any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-846553 Share on other sites More sharing options...
.josh Posted June 1, 2009 Share Posted June 1, 2009 strip_tags Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-846570 Share on other sites More sharing options...
FrumpyJones Posted June 1, 2009 Author Share Posted June 1, 2009 I assume you wanted me to replace line 5 with your nothing-between-the-parenthesis line. I did, now I get this error: Parse error: syntax error, unexpected T_ELSE in /sendhappymail.php on line 25 again.. help? Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-846607 Share on other sites More sharing options...
.josh Posted June 1, 2009 Share Posted June 1, 2009 no, I wanted you to follow the link to the manual and read how to format the arguments correctly. Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-846611 Share on other sites More sharing options...
.josh Posted June 1, 2009 Share Posted June 1, 2009 As far as your error on line 25 (a different error than your previous one), it's because you have no closing bracket for the "if" statement that goes along with that "else". Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-846613 Share on other sites More sharing options...
FrumpyJones Posted June 1, 2009 Author Share Posted June 1, 2009 Couple things: [*]I wasn't trying to be a smart ass with my last post. I was sincerely asking. [*]I didn't write the actual argument in line 5. It was code given to me by another helpful member of this forum [*]I followed the link in your post, and admittedly, I'm lost reading it. [*]I did state in my inital post that I am a total noob to using PHP (Or web programming, for that matter) [*]I'm counthing the {'s in my if/else statements, and they seem to be adding up. I'm obviously missing something, but I'm not sure what. [*]I am very thankful for your help. Please do not think otherwise. Here's my code as it looks right now: <?php function clean($text){ $text=trim($text); $text.=strip_tags('allowed tags'$text); $text.=htmlspecialchars($text,ENT_NOQUOTES); $text.=mysql_real_escape_string($text); $text.=filter_var($text,FILTER_SANITIZE_STRING); } $firstname = clean($_POST['firstname']); $lastname = clean($_POST['lastname']); $phone = $_POST['phone']; $cell = clean($_POST['cell']); $email = $_POST['email']; $comments = clean($_POST['comments']); $valNoBot = clean($_POST['hiddenField']); /*Sending Email*/ if ($valNoBot == "ihateubot"){ $to = "[email protected]"; $subject = "New Contact"; $message = "Form1 Information \n\nFirstname = $firstname\r\nLastname = $lastname\r\nphone number = $phone\r\ncell = $cell\r\ne-mail = $email \nmessage = $comments"; $from = "$firstname $lastname-$email";} str_replace('.','',$from);//replacing dots with nothing else { print "<h3>Go away you stinkin' bot!</h3> \n"; } // end if if(mail($to, $subject, $message, "From: $from")) header("location: contactsuccess.html"); else header("location: contactfailure.html"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-846625 Share on other sites More sharing options...
.josh Posted June 1, 2009 Share Posted June 1, 2009 I didn't think you were being a smartass. I was just clarifying the intention of my post, as it seemed to not be clear. error #1) $text.=strip_tags('allowed tags'$text); That is incorrect. stip_tags requires 1 argument, and an optional 2nd. As it stands right now, you have a string 'allowed tags' mashed together with a variable $text. That's what you are getting your first error from. I'm going to assume you just want to strip all tags from $text, so it should be like so: $text.=strip_tags($text); If there were some tags you do wish to allow, that's where the 'allowed tags' argument comes in, but it should look like this: $text.=strip_tags($text, 'allowed tags'); arguments should be separated by a comma. Also, you would actually want to replace 'allowed tags' with the tags you want to allow. For instance, if you want to strip everything except anchor tags, you would do this: $text.=strip_tags($text, '<a>'); error #2) /*Sending Email*/ if ($valNoBot == "ihateubot"){ $to = "[email protected]"; $subject = "New Contact"; $message = "Form1 Information \n\nFirstname = $firstname\r\nLastname = $lastname\r\nphone number = $phone\r\ncell = $cell\r\ne-mail = $email \nmessage = $comments"; $from = "$firstname $lastname-$email";} str_replace('.','',$from);//replacing dots with nothing else { The part in red is your problem. You have a closing bracket for your if statement at the top there, then you have an expression (the str_replace), then you have an else. The else needs to come immediately after the closing bracket. I'm going to assume that the str_replace is supposed to be inside the 'if' condition so it should be like this: /*Sending Email*/ if ($valNoBot == "ihateubot"){ $to = "[email protected]"; $subject = "New Contact"; $message = "Form1 Information \n\nFirstname = $firstname\r\nLastname = $lastname\r\nphone number = $phone\r\ncell = $cell\r\ne-mail = $email \nmessage = $comments"; $from = "$firstname $lastname-$email"; str_replace('.','',$from);//replacing dots with nothing } else { Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-846851 Share on other sites More sharing options...
trq Posted June 1, 2009 Share Posted June 1, 2009 Another problem I see is that your clean function doesn't return anything. It also make use of the mysql_real_escape_function which requires a databae connection, do you have that? Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-846867 Share on other sites More sharing options...
FrumpyJones Posted June 1, 2009 Author Share Posted June 1, 2009 I may. The code we're all looking at right now was given by dark freaks. My original code did not have strip tags or any mysql calls. I have no DB set up on my web site, but my host probably allows it. I'm not sure what Dark freaks was trying to strip with his strip tags as I see no other assignment to 'allowed tags'. The end result was to remove the periods I was getting in the e-mails sent to me by the form. Again, being a huge novice at this, I wasn't sure how strip tags was accomplishing it, or why the mysql call would be there either, I was just putting faith in the community here as you've helped a lot of people Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-846875 Share on other sites More sharing options...
FrumpyJones Posted June 1, 2009 Author Share Posted June 1, 2009 Now I get this error: Fatal error: Call to undefined function: filter_var() in /sendhappymail.php on line 8 And so we're all working on the same page, here's my code now, followed by the last known working code: <?php function clean($text){ $text=trim($text); $text.=strip_tags($text, 'allowed tags'); $text.=htmlspecialchars($text,ENT_NOQUOTES); $text.=mysql_real_escape_string($text); $text.=filter_var($text,FILTER_SANITIZE_STRING); } $firstname = clean($_POST['firstname']); $lastname = clean($_POST['lastname']); $phone = $_POST['phone']; $cell = clean($_POST['cell']); $email = $_POST['email']; $comments = clean($_POST['comments']); $valNoBot = clean($_POST['hiddenField']); /*Sending Email*/ if ($valNoBot == "ihateubot"){ $to = "[email protected],"; $subject = "New Mail"; $message = "Form1 Information \n\nFirstname = $firstname\r\nLastname = $lastname\r\nphone number = $phone\r\ncell = $cell\r\ne-mail = $email \nmessage = $comments"; $from = "$firstname $lastname-$email"; str_replace('.','',$from);}//replacing dots with nothing else { print "<h3>Go away you stinkin' bot!</h3> \n"; } // end if if(mail($to, $subject, $message, "From: $from")) header("location: contactsuccess.html"); else header("location: contactfailure.html"); ?> <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $phone = $_POST['phone']; $cell = $_POST['cell']; $email = $_POST['email']; $comments = $_POST['comments']; $valNoBot = $_POST['hiddenField']; /*Sending Email*/ if ($valNoBot == "ihateubot"){ $to = "[email protected]"; $subject = "New Mail"; $message = "Form1 Information \n\nFirstname = $firstname\r\nLastname = $lastname\r\nphone number = $phone\r\ncell = $cell\r\ne-mail = $email \nmessage = $comments"; $from = "$firstname $lastname - $email";} else { print "<h3>Go away you stinkin' bot!</h3> \n"; } // end if if(mail($to, $subject, $message, "From: $from")) header("location: contactsuccess.html"); else header("location: contactfailure.html"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-846899 Share on other sites More sharing options...
darkfreaks Posted June 1, 2009 Share Posted June 1, 2009 if you do not have PHP 5 just remove the filter_var function i would suggest reading up on strip_tags()this will explain what html tagsare allowed in the second arguement, and thanks for the admin for the correction. also if you do not have aDB connection mysql_real_escape_string()is not needed. Quote Link to comment https://forums.phpfreaks.com/topic/159443-having-weird-issue-with-php-mailform/#findComment-846907 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.