June 24, 201115 yr Friday afternoons are not my favourite time to get anything done... sooooo, what's my brain farting about here? It's obviously something simple but i'm just not able to spot it! Code <?php if (isset($_POST['submit'])) { if (trim($_POST['email'] == '')) { $hasError = true; } else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+.[A-Z]{2,4}$",trim($_POST['email']))) { $hasError = true; } else { $email = trim($_POST['email']); } if (trim($_POST['message'] == '')) { $hasError = true; } else { $message = trim($_POST['message']); } if (trim($_POST['firstname'] == '')) { $hasError = true; } else { $firstname = trim($_POST['firstname']); } if (trim($_POST['phone'] == '')) { $hasError = true; } else { $phone = trim($_POST['phone']); } if (trim($_POST['surname'] == '')) { $hasError = true; } else { $surname = trim($_POST['surname']); } if (!isset($hasError)) { $emailTo = 'mike@miniman-webdesign.co.uk'; $body = "Name: $firstname $surname nnEmail: $email nnphone: $phone nn Message: $message nn"; $headers = 'From: Medway Contact Form <'.$emailTo.'>'."rn" .'Reply-To: '. $email; mail($emailTo, $subject, $body, $headers); $emailSent = true; } } ?> <html> <head></head> <body> <?php if(isset($hasError)) { ?> <p class="has_error">Ooops try again</p> <?php } ?> <?php if(isset($emailSent) && $emailSent == true) { ?> <p><strong>Email Sent!</strong></p> <p>Thank you <strong><?php echo $name; ?></strong>Your email was successfully sent.</p> <?php } else { ?> <form method="post" action="<?php echo $_SERVER['PHP_SELF']; ?>" class="medway_register_form" id="medway_register_form"> <fieldset> <legend>Contact Form</legend> <ol> <li> <label for="firstname">First Name</label><input type="text" name="firstname" id="firstname" /> </li> <li> <label for="surname">Surname</label><input type="text" name="surname" id="surname" /> </li> <li> <label for="email">Email</label><input type="text" name="email" id="email" class="email" /> </li> <li> <label for="phone">Phone</label><input type="phone" name="phone" id="phone" class="phone" /> </li> <li> <label for="message">Message</label><textarea name="message" id="message" col="80" rows="10"></textarea> </li> <li> <label for="submit"> </label><input type="submit" id="submit" value="Submit" /> </li> </ol> </fieldset> </form> <?php } ?> </body> </html> The form neither sends or displays any errors :/
June 24, 201115 yr try to replace this: if (isset($_POST['submit'])) { by this: if ($_SERVER['REQUEST_METHOD'] == 'POST') { hope this helps
June 24, 201115 yr and do you need a name="submit" on your form? just tested with and you should have got a mail Edited June 24, 201115 yr by zed
June 24, 201115 yr Author Yup got the mail. Which bit did you alter zed? and do you need a name="submit" on your form? Hehe copy and paste blunder Edited June 24, 201115 yr by MikeChipshop
June 24, 201115 yr <label for="submit"> </label><input type="submit" name="submit" id="submit" value="Submit" />
June 24, 201115 yr Author Thank you both for the fixes. In this case it was zed's fix that i missed (always silly things)... however as both fixes work, which would be the ideal one to implement?
Create an account or sign in to comment