webref.eu Posted September 12, 2011 Share Posted September 12, 2011 Hi Guys I am looking for a simple form script which allows a website visitor to provide their telephone number so the website owner can phone them back. The form would need to take the visitor details as follows: Your Name Your Tel Best Time to Call Your Email and then e-mail those details to the website owner. I would be most grateful if anyone could point me in the direction of an example script as I know this is pretty common functionality. Many thanks Quote Link to comment Share on other sites More sharing options...
TOA Posted September 12, 2011 Share Posted September 12, 2011 1. Build your form 2. In the processing, add the $_POST data to your email body 3. Use mail() to send the email Any mail script you find on google will do this. If you make an attempt, I'm sure the community here will be more than happy to help if you run into trouble. Quote Link to comment Share on other sites More sharing options...
webref.eu Posted September 12, 2011 Author Share Posted September 12, 2011 Sure thing, I have started coding it from scratch, but if anyone can give me urls of good example scripts (for telephone callback or contact forms) that would be much appreciated, as it will speed things up for me. Many thanks Quote Link to comment Share on other sites More sharing options...
webref.eu Posted September 13, 2011 Author Share Posted September 13, 2011 Any links to good sample scripts then please guys? Rgds Quote Link to comment Share on other sites More sharing options...
SparK_BR Posted September 13, 2011 Share Posted September 13, 2011 I would tell you to google it or go to php.net, but I think that would be kinda rude. ok, first make sure your form has the method atribute set to post: <form method="post" then on the target atribute place your script url target="callMe.php" so when the client submits the form, it will send the values of the inputs by name within the $_POST array then validate the data, check if the email smells like an email and etc. then use the mail() function! you can look here for reference and samples. another alternative is control the form with jQuery and use the .post() function, so you can check the result and show error messages to the user, but that's GUI and AJAX, the PHP will still be the same. Quote Link to comment Share on other sites More sharing options...
TOA Posted September 13, 2011 Share Posted September 13, 2011 <?php /* should give you an email that looks like: Subject: Call-back John Doe 555-555-5555 After 6 PM user@email.com */ if (strtolower($_SERVER['REQUEST_METHOD']) == "post") { // process code here $to = "THE EMAIL ADDRESS YOU WANT IT SENT TO HERE"; $subject = "Call-back"; $body = ""; foreach ($_POST as $value) { $body .= "$value\r\n"; } if (!mail($to, $subject, $body)) { // handle error echo "Sorry, there was an error"; } else { // handle successful send echo "Email was successfully sent"; } } else { // display form here ?> <form action="" method="post"> <input type="text" name="Name" value="" /> <input type="text" name="Phone" value="" /> <input type="text" name="BestTime" value="" /> <input type="text" name="Email" value="" /> <input type="submit" value="Submit" /> </form> <?php } ?> Note that this has no validation or cleansing involved. It's just to get you started. Quote Link to comment 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.