I have a html page with all images and other text. Below i have the contact form. i am new to php. I have used php to send mail. But when i click on send button,it is going to backend.php. And i have a blank page. What i need is it should in the same page. I have done some javascript to show and hide div’s. With this i am showing a thank u msg in the same page. But i dont want to redirect browser to show it is going to backend.php.TO be in the same page i have redirected php to another window.
My code is –
backend.php
<?php
if($_POST['message'])
{
$body = "Name: ".$_POST['name'];
$body .= "<br>Email: ".$_POST['email'];
$body .= "<br>Phone/Mobile: ".$_POST['phone']
$body .= "<br>Address: ".$_POST['address']
$body .= "<br>Message: ".$_POST['msg']
if(mail("Info@travelfoodservices.com","Subjects",$body))
echo 'true';
else echo 'false;';
}
?>
form code –
<form onsubmit="return validateFormOnSubmit(this)" action="backend.php" method="post" target="_blank">
<table align="left">
<tbody>
<tr>
<td align="left"><label for="name">Enter your name:</label> <label style="color:red;display:none;font-size:18px;" Id="namestar">*</label></td>
</tr>
<tr><td align="left"><input Id="name" name="name" style="width:515px;" size="35" maxlength="50" type="text"></td></tr>
<tr ><td height="12px"/></tr>
<tr>
<td align="left"><label for="email">Email Address:</label> <label style="color:red;display:none;font-size:18px;" Id="emailstar">*</label></td>
</tr>
<tr><td align="left"><input Id="email" name="email" style="width:515px;" type="text"></td></tr>
<tr><td height="12px"/></tr>
<tr>
<td align="left"><label for="phone">Phone/Mobile:</label><label style="color:red;font-size:18px;display:none;" Id="phonestar">*</label></td>
</tr>
<tr><td align="left"><input Id="phone" name="phone" style="width:515px;" type="text"></td></tr>
<tr><td height="12px"/></tr>
<tr>
<td align="left"><label for="address">Your Address:</label><label style="color:red;font-size:18px;display:none;" Id="addressstar">*</label></td>
</tr>
<tr><td align="left"><input id="address" name="address" style="width:515px;" type="text"></td></tr>
<tr><td height="12px"/></tr>
<tr>
<td align="left"><label for="msg">Enter Your Comments / Suggestions / Enquiries</label><label style="color:red;font-size:18px;display:none;" Id="messagestar">*</label></td>
</tr>
<tr><td align="left"><textarea id="msg" name="msg" style="width:515px;height:100px;" type="text"></textarea></td></tr>
<tr><td height="12px"/></tr>
<tr>
<td align="right"><table align="left">
<tbody>
<tr >
<td style="width:160px;"/>
<td style="width:250px;" ><label Id="mandatory" style="display:none;color:red;" >* Mandatory fields</label></td>
<td ><input type="submit" name="send" value="send" /></td><td >
<input type="reset" name="reset" value="reset" onclick="resetAll()" /></td></tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
I would move the backend.php script to the top of the page that the form is in. To do this, the form script (“HTML page” as you referred to it) would need to be a .php page rather than a .html page. I’ll assume here that you would call it form.php: