Need help with PHP Form

Hello all - Firstly, this query might be already repeated and coming up yet another time. I would appreciate if someone can direct me to the appropriate thread if this is already answered. If not, would be really helpful if someone can take out their precious time and knowledge to help me out.

I’m a naive programmer and learning PHP basically. For my website, I have the following requirement.
Someone coming to my landing page, entering their details and pressing submit, their details needs to be e-mailed and then they need to be shown a thank you page.
For this, I have the following code in the main page

		[php]<form id="josform" name="josForm" action="http://www.xxx.com/thank.php" method="post" class="form-validate">
				<tr>
					<td><strong>Name</strong><br /><input name="name" id="form_name" type="text" class="form-field" /></td>
				</tr>
				<tr>
					<td><strong>Email</strong><br /><input name="email" id="form_email" type="text" class="form-field" /></td>
				</tr>
				<tr>
					<td><strong>Mobile</strong><br /><input name="phone" id="form_mobile" onKeyPress="return checkIt(event)" type="text" class="form-field" /></td>
				</tr>
				<tr>
					<td>					
					<input type="hidden" name="source" value=""/>
                 
			<input type="submit" id="submit" name="submit" value="Submit" class="form-btn" onclick="return checkval_form()"  /></td>
					
			</tr>
		</form>[/php]

Basically this code is getting inputs from user and in the action, the thank you page link is given.
The code snippet of thank you page code is as below

[php]

Thankyou page Thank you for your sharing your details. We will get back to you soon.
This page will redirect in 5 seconds.. [/php]

The redirection is all working fine. Now what I need to do to have the e-mail sent to me with all input details? But the e-mail should NOT be dispayed in the webpage view source code. I think I need to put up a PHP script on my server and have it linked. This is where I have no clues and trying to get help.
Basically need to know how to link my main page to the file which shall send the actual email and then redirect to the thank you page.

Advance thanks for your time and help. I have been trying to find the answer on internet but unable to understand how the actual codes shall look.

Here is your script. I have included all the functionality on one page you can split it accordingly. One more thing I haven’t used any server side validation, use it don’t just rely on client side validation.

[php]<?php
session_start();

	if(	$_SERVER['REQUEST_METHOD'] == 'POST' &&
		isset($_POST['submit']) == 'submit'
		){

		$to = '[email protected]'; // To whom you want to send information.
		$subject = 'An Email from' . $_POST['name'];
		$message = 	'You have received a new email from' . $_POST['name'] .
					'<br> His / Her phone number is ' . $_POST['phone'];


		 if (mail($to, $subject, $message)){

		 	$_SESSION['message'] = '<div id="ref_message"><h2>Thank you for sharing your details. We will get back to you soon.</h2></div>';
		 } else {

		 		$_SESSION['message'] = '<div id="ref_message"><h2>Sorry We are having some problems please try again.</h2></div>';
		 }

	}

?>

<?php
		if ($_SERVER['REQUEST_METHOD'] == 'GET')
			{echo 'Submit Your Information'; }

		if ($_SERVER['REQUEST_METHOD'] == 'POST')
			{echo 'Thank You'; }
	?>
</title>
label.form-field { width: 3em; float: left; text-align: left; margin-right: 0.5em; display: block } #ref_message{ margin-bottom:5px; padding: 10px; width: 400px; border: 2px dotted red; text-align: justify; } <?php

if ($_SERVER[‘REQUEST_METHOD’] == ‘GET’)
{echo ‘

Please Fill all the fields

’; }

if (isset($_SESSION[‘message’]))
{
echo $_SESSION[‘message’];
session_destroy();
$_SESSION = array();
}
?>

<p>
	<label for="name" class="form-field">Name: </label>
	<input type="text" name="name" id="name" class="form-field" required>
</p>

<p>
	<label for="email" class="form-field">Email: </label>
	<input type="email" name="email" id="email" class="form-field" required>
</p>

<p>
	<label for="phone" class="form-field">Phone: </label>
	<input type="text" name="phone" id="phone" class="form-field" required>
</p>

<p><input type="submit" name="submit" id="Submit">
</p>
[/php]
Sponsor our Newsletter | Privacy Policy | Terms of Service