silviya Posted November 23, 2009 Share Posted November 23, 2009 Hello there. I've been having trouble with an email form. Can't find the problem really. I've tested so many times, tried different ifs to see where the problem comes from. It turned out its alway the last ELSE. The one that doesnt have explanation to me. Here we go: if(isset($_GET['send'])) { $email=filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); //$email = htmlentities($email,ENT_QUOTES); $body=stripslashes($_POST['body']); $date = date("F j, Y, g:i a"); $valid = preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i','09_az..AZ@host.dOMain.cOM'); $spam=preg_match('/(\r|\n)(to:|from:|cc:|bcc:)/',$body); $ip = substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'], ".")); if ($email && $body && $valid && !$spam) { if ( mail( $to, "Feedback Form Results", $body, "From: $email" )) { echo '<p>'.$thanks.'</p>'; $email=''; $body=''; } else { echo '<p>'.$error.'</p>'; $email=''; $body=''; } } else if ($spam) { echo '<p>'.$spamattack.'</p>'; $email=''; $body=''; } else { echo'<p><strong>'.$fillin.'</strong></p>'; $email=''; $body=''; } } Quote Link to comment https://forums.phpfreaks.com/topic/182633-email-form-cannot-find-the-problem/ Share on other sites More sharing options...
cags Posted November 23, 2009 Share Posted November 23, 2009 var_dumb out these values before going into the if statement and find out which one is failing, $email, $body, $valid and $spam. Quote Link to comment https://forums.phpfreaks.com/topic/182633-email-form-cannot-find-the-problem/#findComment-963908 Share on other sites More sharing options...
cags Posted November 23, 2009 Share Posted November 23, 2009 Erm, you can try var_dumb, but you'll probably have more look with var_dump. Come on, own up, which admin stood the p up on end? Quote Link to comment https://forums.phpfreaks.com/topic/182633-email-form-cannot-find-the-problem/#findComment-963923 Share on other sites More sharing options...
prasanthmj Posted November 23, 2009 Share Posted November 23, 2009 To debug this, you have to check the HTML code for the form. Chck if the submit button is named "send" or "Send" or something else. Quote Link to comment https://forums.phpfreaks.com/topic/182633-email-form-cannot-find-the-problem/#findComment-963940 Share on other sites More sharing options...
silviya Posted November 23, 2009 Author Share Posted November 23, 2009 string(13) "test@test.com" string(24) "rrrr " int(1) int(0) I've checked so many times. <form method="post" action="contacts.php?send"> <label for="email">Email:</label> <input name="email" type="text" value="<?php echo htmlspecialchars($email); ?>" size="30"><br /> <label for="body"> Message:</label><br /> <textarea name="body" rows="15" cols="40"><?php echo htmlspecialchars($body); ?> </textarea><br /> <input type="submit" value="Send" name="send"/> </form> Quote Link to comment https://forums.phpfreaks.com/topic/182633-email-form-cannot-find-the-problem/#findComment-963950 Share on other sites More sharing options...
cags Posted November 23, 2009 Share Posted November 23, 2009 Ok, based on those values, the first if statement evaluates to true, meaning it should get as far as calling the mail function. Yet you said it goes into the final else? Quote Link to comment https://forums.phpfreaks.com/topic/182633-email-form-cannot-find-the-problem/#findComment-963956 Share on other sites More sharing options...
silviya Posted November 23, 2009 Author Share Posted November 23, 2009 What i meant was i tried different ifs. i removed the mail() function and added only if (!$email) etc. I keep all the results at home, a couple of hours later ill post them out. Actually if i remember correct i had problems with $valid...once i made it to the final ELSE that was placed for any other mistake. Ill post more tonight. Quote Link to comment https://forums.phpfreaks.com/topic/182633-email-form-cannot-find-the-problem/#findComment-963963 Share on other sites More sharing options...
mrMarcus Posted November 23, 2009 Share Posted November 23, 2009 your indenting is off .. fixed code: <?php if(isset($_GET['send'])) { $email=filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); //$email = htmlentities($email,ENT_QUOTES); $body=stripslashes($_POST['body']); $date = date("F j, Y, g:i a"); $valid = preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i','09_az..AZ@host.dOMain.cOM'); $spam=preg_match('/(\r|\n)(to:|from:|cc:|bcc:)/',$body); $ip = substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'], ".")); if ($email && $body && $valid && !$spam) { if ( mail( $to, "Feedback Form Results", $body, "From: $email" )) { echo '<p>'.$thanks.'</p>'; $email=''; $body=''; } else { echo '<p>'.$error.'</p>'; $email=''; $body=''; } } else if ($spam) { echo '<p>'.$spamattack.'</p>'; $email=''; $body=''; } else { echo'<p><strong>'.$fillin.'</strong></p>'; $email=''; $body=''; } } ?> so, this is not working for you: if ($email && $body && $valid && !$spam) { check through those $vars to see what's going on. check $valid as '09_az..AZ@host.dOMain.cOM' this might not be working for you. Quote Link to comment https://forums.phpfreaks.com/topic/182633-email-form-cannot-find-the-problem/#findComment-963964 Share on other sites More sharing options...
cags Posted November 23, 2009 Share Posted November 23, 2009 so, this is not working for you: if ($email && $body && $valid && !$spam) { check through those $vars to see what's going on. check $valid as '09_az..AZ@host.dOMain.cOM' this might not be working for you. If you read the thread you'll see that I already asked the OP to show us those values. If you check the output given you'll also see that row evaluates as true. Meaning that the problem appears to be with the call to mail. Having said that I can't see any reason it would fail, assuming the server is setup correctly. I'd probably add "\r\n" to the end of the header, but I don't believe it's required after the last header item. The script as is doesn't contain values for $error, $thanks, $spamattack or $fillin. Which would make it fairly difficult to calculate exactly which block is being entered. Quote Link to comment https://forums.phpfreaks.com/topic/182633-email-form-cannot-find-the-problem/#findComment-963975 Share on other sites More sharing options...
silviya Posted November 24, 2009 Author Share Posted November 24, 2009 Hello everyone, thanks for the replies! with this: $email=filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); //$email = htmlentities($email,ENT_QUOTES); $body=stripslashes($_POST['body']); $date = date("F j, Y, g:i a"); $valid = preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i','09_az..AZ@host.dOMain.cOM'); $spam=preg_match('/(\r|\n)(to:|from:|cc:|bcc:)/',$body); $ip = substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'], ".")); if ($email && $body && $valid && !$spam) { if ( mail( $to, "Feedback Form Results", $body, "From: $email" )) {..... i got this error: Warning: mail() [function.mail]: SMTP server response: 530 SMTP authentication is required. in C:.... on line 95 We encountered problem while sending your message! The problem is probably due to a server error. We appologise for the inconvinience. Please try again. with //$email=filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); $email = htmlentities($email,ENT_QUOTES); $body=stripslashes($_POST['body']); $date = date("F j, Y, g:i a"); $valid = preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-])([a-z0-9])+)*$/i','09_az..AZ@host.dOMain.cOM'); $spam=preg_match('/(\r|\n)(to:|from:|cc:|bcc:)/',$body); $ip = substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'], ".")); if ($email && $body && $valid && !$spam) { if ( mail( $to, "Feedback Form Results", $body, "From: $email" )) { i got Notice: Undefined variable: email in C:\wamp\www\torch\web\contacts.php on line 87 Please fillin valid email address I honestly got totally lost in the different tests... Quote Link to comment https://forums.phpfreaks.com/topic/182633-email-form-cannot-find-the-problem/#findComment-964544 Share on other sites More sharing options...
silviya Posted November 24, 2009 Author Share Posted November 24, 2009 if(isset($_GET['send'])) { $email=filter_var($_POST['email'], FILTER_SANITIZE_EMAIL); // $email = htmlentities($email,ENT_QUOTES); $body=stripslashes($_POST['body']); $date = date("F j, Y, g:i a"); $valid = filter_var($_POST['email'], FILTER_VALIDATE_EMAIL); //$valid = preg_match('/^([a-z0-9])(([-a-z0-9._])*([a-z0-9]))*\@([a-z0-9])*(\.([a-z0-9])([-a-z0-9_-)([a-z0-9])+)*$/i','09_az..AZ@host.dOMain.cOM'); $spam=preg_match('/(\r|\n)(to:|from:|cc:|bcc:)/',$body); $ip = substr($_SERVER['REMOTE_ADDR'], 0, strrpos($_SERVER['REMOTE_ADDR'], ".")); if ($email && $body && $valid && !$spam) { if (mail( $to, "Feedback Form Results", $body, "From: $email" )) { fails on $valid Quote Link to comment https://forums.phpfreaks.com/topic/182633-email-form-cannot-find-the-problem/#findComment-964585 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.