alexis_d Posted June 16, 2007 Share Posted June 16, 2007 Please pardon the noobiness; hopefully someone will find this easy to solve. I have an email feedback form that I'd like to have do two things: 1. Collect a few pieces of information & mail them to the owner of the site 2. Send a confirmation email to the user at the email address they provide. Simple, right? There are two problems I haven't solved: 1. I still need an email validator. I can check to see if something's in that field, but not whether it conforms to standard email address syntax. 2. The confirmation email is going out just fine, but it's basically a zombie. It's the same email regardless of what message/inputs the user puts in the form fields. I still need that information to be captured and sent to the owner of the site. I'm using Larry Ullman's PHP and MYSQL for dynamic websites Visual QuickPro guide as the model code, and I'm a little ticked at Larry that the email function is documented in such a cursory way. ::shakes fist:: If anyone can help solve the above problems, I would be greatly appreciative. The code I'm using is below. ___________________________________________________ <?php # Script 3.15 - register.php if (isset($_POST['submit'])) { // Handle the form. $message = NULL; // Create an empty new variable. // Check for a name. if (strlen($_POST['name']) > 0) { $name = TRUE; } else { $name = FALSE; $message .= '<p>Please enter your name.</p>'; } // Check for an email address. if (strlen($_POST['email']) > 0) { $email = TRUE; } else { $email = FALSE; $message .= '<p>Please let us know where it\'s best to email you.</p>'; } // Check for message text. if (strlen($_POST['text']) > 0) { $text = TRUE; } else { $text = FALSE; $message .= '<p>Please enter a message.</p>'; } if ($name && $email && $text) { // If everything's okay. // Register the user. // Send confirmation to customer. $body = "Thanks for your message. We look forward to reading it. \n\nSincerely,\nJoe Palooka, Acme Widget, Inc."; mail ($_POST['email'], 'Thank you for your message!', $body, 'From: customerservice@client.com'); // Send an email with customer message. $storemail .= 'testrecipient@client.com';//destination email mail ($storemail, $name, $text,'From: customerservice@client.com'); header ('Location: thankyou.php'); exit(); } else { $foo .= '<p>Please try again.</p>'; //I just sent this off into oblivion by calling it $foo, 'cause I don't know what else to do with it. } } ?> Thanks again for having a look. -Alexis Quote Link to comment https://forums.phpfreaks.com/topic/55807-simple-noob-email-question-deadline-close-though/ Share on other sites More sharing options...
emehrkay Posted June 16, 2007 Share Posted June 16, 2007 i made a change to how you're checking the fields for value and added the email regex <?php if (trim($_POST['email']) !== '') { $email = TRUE; if(!eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $_POST['email'])) $email = false; } else { $email = FALSE; $message .= '<p>Please let us know where it\'s best to email you.</p>'; } ?> i canged strlen to trim because a person could put a bunch of spaces in the field and it still passes the strlen check Quote Link to comment https://forums.phpfreaks.com/topic/55807-simple-noob-email-question-deadline-close-though/#findComment-275668 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.