staples27 Posted June 2, 2009 Share Posted June 2, 2009 hi I have a problem with a PHP email script I've been using. It tends to submit blank data to my email address every time I enter the page it's coded into. All I remember was following a tutorial at college on how to do it. The script is as follows ( if anyone can suggest a better script than this then that would be appreciated ): <?php error_reporting(0); $name = $_POST['name']; $email = $_POST['email']; $subject = $_POST['subject']; $message = $_POST['message']; $to = '[email protected]'; $subject = "$subject"; $message = "Name: $name, Email: $email, Message: $message"; $headers = "From: $email"; mail($to, $subject, $message, $headers); function VerifyForm(&$values, &$errors) { if (strlen($values['name']) < 1) $errors['name'] = 'Please enter your name'; if (!ereg('.*@.*\..{2,4}', $values['email'])) $errors['email'] = 'Please enter a valid email'; if (strlen($values['message']) < 1) $errors['message'] = 'Please enter a message'; return (count($errors) == 0); } function DisplayForm($values, $errors) { ?> Then the very last bit of code of the page <?php } function ProcessForm($values) { echo ( "<div id=maincontent>Thank you, your email has been sent! <a href=\"javascript:history.back()\">Click here to go back</a></div>" ); } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $formValues = $_POST; $formErrors = array(); if (!VerifyForm($formValues, $formErrors)) DisplayForm($formValues, $formErrors); else ProcessForm($formValues); } else DisplayForm(null, null); ?> Thanks in advance for any help! Link to comment https://forums.phpfreaks.com/topic/160604-php-mail-script-problem/ Share on other sites More sharing options...
cltn77 Posted June 2, 2009 Share Posted June 2, 2009 your $_SERVER['REQUEST_METHOD'] currently is "get" instead of "post", so it will not go to the VerifyForm function. Please check. Link to comment https://forums.phpfreaks.com/topic/160604-php-mail-script-problem/#findComment-847602 Share on other sites More sharing options...
staples27 Posted June 2, 2009 Author Share Posted June 2, 2009 hmm I'm not sure I understand you, it is set to 'POST' ??? the form does go through the verify function once I hit submit, the problem is the form also submits itself with blank data to my email address whenever I enter the page it's coded on... Link to comment https://forums.phpfreaks.com/topic/160604-php-mail-script-problem/#findComment-847605 Share on other sites More sharing options...
deepson2 Posted June 2, 2009 Share Posted June 2, 2009 you are not written $headers value in your code. put that and check what is the status now. Link to comment https://forums.phpfreaks.com/topic/160604-php-mail-script-problem/#findComment-847712 Share on other sites More sharing options...
staples27 Posted June 2, 2009 Author Share Posted June 2, 2009 could you explain a bit more how I would do this? i'm no php expert Link to comment https://forums.phpfreaks.com/topic/160604-php-mail-script-problem/#findComment-847785 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.