derrick1123 Posted March 12, 2008 Share Posted March 12, 2008 How come this isn't working? Well for one I made it so that might be why...but still. <? $step = $_POST['step']; if($step==0 || $step==""){ echo " <form action='index.php' method='post'> <input type='hidden' value='1' name='step'> Your Name: <input type='text' name='name' size=30><br> <br> Email Address: <input type='text' name='email' size=30><br> <br> Subject: <input type='text' name='subject' size=30><br> <br> Message<br> <textarea cols=30 rows=6 name='message' wrapping='virtual'></textarea><br> <br> <input type='submit' value='Send!'> </form> "; } if($step=="1"){ // EDITABLE AREA \\ $error_page = "error.htm"; // Url of the error (fail) page $thx_page = "thankyou.htm"; // Url of the thank you (success) page $form_url = "sendemail.htm"; // Url of the form you used before $max_message_len = 9999; // Max length of message $to = "[email protected]"; // Email address to send email to // END EDITABLE AREA - do not edit below here! \\ $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; // Error Checking $e = 0; if($name=="" || $name == NULL || $name == 0 || strlen($name)<3){ $e++; } if(strpos($email, "@")===false || strpos($email, ".")===false || strlen($email)<5){ $e++; } if($subject=="" || $subject == NULL || $subject == 0 || strlen($subject)<2){ $e++; } if(strlen($message)>$max_message_len || strlen($message)<5){ $e++; } // Go for it if($e>0){ die( "<meta http-equiv='REFRESH' content='0;url=$error_page'>" ); } else { $message = nl2br($message); $message = "<font face='verdana' size=4>Message from: $form_url: $name <$email> <hr> $message <hr> </font>"; mail($to, $subject, $message, "From: $name <$email>\r\nX-Mailer: $form_url \r\nContent-type: text/html; charset=UTF-8" ); echo "<meta http-equiv='REFRESH' content='0;url=$thx_page'>"; } } ?> BTW, this is the whole thing...there are no other pages. Link to comment https://forums.phpfreaks.com/topic/95754-email-script-i-made-not-working-shock/ Share on other sites More sharing options...
cunoodle2 Posted March 12, 2008 Share Posted March 12, 2008 What exactly is happening after someone fills out the form and hits submit? Are there any error messages? Does it even make it into this if statement.. if($step=="1"){ Link to comment https://forums.phpfreaks.com/topic/95754-email-script-i-made-not-working-shock/#findComment-490263 Share on other sites More sharing options...
derrick1123 Posted March 12, 2008 Author Share Posted March 12, 2008 It shows the error page from the code: if($e>0){ die( "<meta http-equiv='REFRESH' content='0;url=$error_page'>" ); } the error page which is error.htm which is nothing right now. Link to comment https://forums.phpfreaks.com/topic/95754-email-script-i-made-not-working-shock/#findComment-490265 Share on other sites More sharing options...
cunoodle2 Posted March 12, 2008 Share Posted March 12, 2008 Try finding out where the error is coming from by doing this... $error = ""; $e = 0; if($name=="" || $name == NULL || $name == 0 || strlen($name)<3){ $error = "Name\n"; $e++; } if(strpos($email, "@")===false || strpos($email, ".")===false || strlen($email)<5){ $error .= "Email\n"; $e++; } if($subject=="" || $subject == NULL || $subject == 0 || strlen($subject)<2){ $error .= "Subject\n"; $e++; } if(strlen($message)>$max_message_len || strlen($message)<5){ $error .= "Message\n"; $e++; } // Go for it if($e>0){ echo "<b>Error Message:</b>".$error; exit(); //die( "<meta http-equiv='REFRESH' content='0;url=$error_page'>" ); } Try that change just to see where the error is occurring and then trace back from there. A simple echo to the screen can save you lots of work. Link to comment https://forums.phpfreaks.com/topic/95754-email-script-i-made-not-working-shock/#findComment-490280 Share on other sites More sharing options...
derrick1123 Posted March 12, 2008 Author Share Posted March 12, 2008 Error Message:Name Subject That is the error I got. Link to comment https://forums.phpfreaks.com/topic/95754-email-script-i-made-not-working-shock/#findComment-490281 Share on other sites More sharing options...
cunoodle2 Posted March 13, 2008 Share Posted March 13, 2008 Ok. To me then that means that there seems to be something happening improperly to both the "$name" as well as the "$subject" variables. Lets do a little more trouble shooting... Add a few lines in the middle here.... // Go for it if($e>0){ echo "<b>Name Value:</b>--".$name."--<br />\n"; echo "<b>Email Value:</b>--".$email."--<br />\n"; echo "<b>Subject Value:</b>--".$subject."--<br />\n"; echo "<b>Message Value:</b>--".$message."--<br /><br />\n"; echo "<b>Error Message:</b>".$error; exit(); //die( "<meta http-equiv='REFRESH' content='0;url=$error_page'>" ); } Always try echoing items to the page while you are testing. That way you can see exactly what the value of a variable contains at any given time. Note that I put the "--" before and after echoing the variables. That way if you see "--0--" that means the variable contains the value of zero. But if you see this "----" you will see that the variable (for whatever the reason) is completely empty. Try it out and let me know. Link to comment https://forums.phpfreaks.com/topic/95754-email-script-i-made-not-working-shock/#findComment-491050 Share on other sites More sharing options...
derrick1123 Posted March 13, 2008 Author Share Posted March 13, 2008 I will try this, thank you. Link to comment https://forums.phpfreaks.com/topic/95754-email-script-i-made-not-working-shock/#findComment-491051 Share on other sites More sharing options...
derrick1123 Posted March 13, 2008 Author Share Posted March 13, 2008 Errors: Name Value:--sample name-- Email Value:[email protected] Subject Value:--samle subject-- Message Value:--This is my very short sample msg. ^.^-- Error Message:Name Subject Link to comment https://forums.phpfreaks.com/topic/95754-email-script-i-made-not-working-shock/#findComment-491053 Share on other sites More sharing options...
cunoodle2 Posted March 13, 2008 Share Posted March 13, 2008 Ok. So it definitely has the proper values. Let's focus now on WHY it's generating the error. It is triggering something in here... "if($name=="" || $name == NULL || $name == 0 || strlen($name)<3)" And in here... "if($subject=="" || $subject == NULL || $subject == 0 || strlen($subject)<2)" I'm guess it has something to do with either the word NULL or the value of zero (which is what I'm guessing the error is). I'm willing to bet that it has something to do with the way that php handles if comparisons between strings and integers which is effectively what you are doing here. Try running this code right AFTER where you added all of those lines echoing the values to the screen... $name_test = ""; if($name=="") {$name_test .= "Empty test <br />\n";} if($name == NULL) {$name_test .= "Null test <br />\n";} if($name == 0) {$name_test .= "Zero test <br />\n";} if(strlen($name)<3) {$name_test .= "String Length test <br />\n";} echo "Name error is coming from: ".$name_test; I hope you are learning something from all of this. This is just a different way to troubleshoot things. If you ever think there is an error in your code you can simply echo to the screen to see what is "really" going on. Run this stuff and then let me know what your next step is gonna be. Link to comment https://forums.phpfreaks.com/topic/95754-email-script-i-made-not-working-shock/#findComment-491063 Share on other sites More sharing options...
derrick1123 Posted March 13, 2008 Author Share Posted March 13, 2008 Thank you for helping me, but here are my errors: Name error is coming from: Zero test Subject error is coming from: Zero test Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry. in C:\xampp\htdocs\email\index.php on line 98 I think I know why the SMTP isn't working... Link to comment https://forums.phpfreaks.com/topic/95754-email-script-i-made-not-working-shock/#findComment-491069 Share on other sites More sharing options...
derrick1123 Posted March 13, 2008 Author Share Posted March 13, 2008 Thank you for helping me, but here are my errors: Name error is coming from: Zero test Subject error is coming from: Zero test Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry. in C:\xampp\htdocs\email\index.php on line 98 I think I know why the SMTP isn't working... ---- Ok I guess I don't know >.< Link to comment https://forums.phpfreaks.com/topic/95754-email-script-i-made-not-working-shock/#findComment-491080 Share on other sites More sharing options...
cunoodle2 Posted March 14, 2008 Share Posted March 14, 2008 Ok so the error definetely has to do with the way that php handles if comparisons between integers (in this case 0) and strings. So you need to take these lines... if($name=="" || $name == NULL || $name == 0 || strlen($name)<3) if($subject=="" || $subject == NULL || $subject == 0 || strlen($subject)<2) And change them to this... if($name=="" || $name == NULL || strlen($name)<3) if($subject=="" || $subject == NULL || strlen($subject)<2) Try that out and then post your findings back on here. Link to comment https://forums.phpfreaks.com/topic/95754-email-script-i-made-not-working-shock/#findComment-492451 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.