I have an html form that inputs data and calls a php script to write the data to an SQL database and then send an email. It used to work fine. It sits on my localhost. It is a test for a website. I test everything on localhost before uploading to the web. Now I find it writes to the SQL table alright but it doesn't send an email and it doesn't move from the html page, the form. I press submit and I get a message 'waiting for localhost' which will eventually timeout. I've put 'trace' 'print' messages in the php script hoping they'd display and show me how far through the script it gets. But nothing displays. It is probably something gone wrong with my IIS setup, I guess, that's disabled the emailing function. But regardless of what the cause it I'd like to know how one best goes about tracking it down. Is there a debug function or addon package we can use with PHP? That will appear on the screen in situations such as mine, when called from an html form?
What's the ACTION value of the form ? I mean the targetted page to which you are sending the user inputs ?
<form action="feedback.php" method="post"> And here is 'feedback.php' with names changed. You'll see it has the required lines for use on the web as well as the required text for use locally. I comment out as required. <? // mail it $mailto = 'myself@yahoo.com' ; $subject = "Feedback Form" ; $webmasteraddress = "webmaster@website.com"; $webmastername = "webmaster"; $formurl = "feedback.html" ; $errorurl = "error.html" ; $thankyouurl = "thankyou.html" ; $uself = 0; $headersep = (!isset( $uself ) || ($uself == 0)) ? "\r\n" : "\n" ; $username = $_POST['username'] ; $firstname = $_POST['firstname'] ; $email = $_POST['email'] ; $comments = $_POST['comments'] ; $secondname = $_POST['secondname'] ; $country = $_POST['country'] ; $phone = $_POST['phone'] ; $IP = $_SERVER["REMOTE_ADDR"]; $findme = "jonn"; $blacklisted = "No"; $pos = strpos($username, $findme); if($pos !== false){$blacklisted = "Yes";} if( $blacklisted != "Yes") { // do write to database now--------------------------- // $link = mysql_connect("localhost", "websitehostsqlloginname", "password") or die("Could not connect : " . mysql_error()); $link = mysql_connect("localhost", "root", "password") or die("Could not connect : " . mysql_error()); print "Connected successfully<p>"; //$DB = "incoming"; $DB = "pkguest"; $table = "clients"; mysql_select_db($DB) or die ("Database $DB not select.." . mysql_error()); print "Successfully selected the Database: $DB "; $query = "INSERT INTO $table(username,firstname,secondname,email,country,phone,comments,IP) values('$username','$firstname','$secondname','$email','$country','$phone','$comments','$IP')"; if ( ! mysql_query( $query, $link) ) die ( "MySQL error.....<p>" .mysql_error() ); print "<p>Successfully added data to table : $table"; } $http_referrer = getenv( "HTTP_REFERER" ); if (!isset($_POST['email'])) { header( "Location: $formurl" ); print "Exit on http_referer"; exit ; } //if (empty($name) || empty($email) || empty($comments)) { // header( "Location: $errorurl" ); // exit ; //} if ( ereg( "[\r\n]", $username ) || ereg( "[\r\n]", $email ) ) { header( "Location: $errorurl" ); exit ; } if (get_magic_quotes_gpc()) { $comments = stripslashes( $comments ); } $messageproper = "This message was sent from:\n" . "$http_referrer\n" . "------------------------------------------------------------\n" . "UserName of sender: $username\n" . "Firstname of sender: $firstname\n" . "Secondname of sender : $secondname\n" . "Country of sender : $country\n" . "Phone number of sender: $phone\n" . "Email of sender: $email\n" . "IP of sender: $IP\n" . "Blacklisted: $blacklisted\n" . "------------------------- COMMENTS -------------------------\n\n" . $comments . "\n\n------------------------------------------------------------\n" ; mail($mailto, $subject, $messageproper, "From: \"$username\" <$email>" . $headersep . "Reply-To: \"$username\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.07" ); header( "Location: $thankyouurl" ); print "about to exit routine"; exit ; ?>
ereg() is a depreciated function. Have you tried debugging it so that which line is causing the real issue. I mean is it the mailing part or the db part ?
Try echoing some msg to check the functions are executed. Or comment out some functions and see if the rest of code is working. This will filter out and gives you the line or function that causes the real issue. Then investigate regarding that line or function. Check whether the parameters passed (if any) are correct, etc..
I'll look up that web services integration thing whatever it is. I've been using print and echo statements, the point is that they don't show over the calling html page which is still onscreen. Funny that. Error messages show - I left a semi colon out and the parser (or something) took over the screen and told me I was wrong. But my 'prints' and 'echo' produce nothing. I should have made that clear. Sorry. That's why I came here. Perhaps I should also make very clear that the script writes to the database okay. No problem there. The immediate problem with the script is that it doesn't go anywhere. It hangs on the html page apparently waiting for localhost (message at bottom of screen). It might have actually done everything. Sent the emails. I think the way it all works the emails are not actually sent from IIS SMTP but are put in a 'dropbox', yes? I should look for that drop box. See if it is getting that done. But what all this has done, of course, is raise the question of how to debug such a situation? Perhaps there's a simple, easy way to get the html page off the screen and make it available for echo output and such? I was actually hoping there might be a php specific debugger we could run with the script but apparently not so.