Jump to content

Example "Request a Callback" Form Script Wanted Please


webref.eu

Recommended Posts

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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.

 

Link to comment
Share on other sites

<?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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.