Sending mail from html through php will return to php page. It should be in the same contact form. How to do it?

Posted by Ershad on Stack Overflow See other posts from Stack Overflow or by Ershad
Published on 2011-02-08T07:21:27Z Indexed on 2011/02/08 7:25 UTC
Read the original article Hit count: 153

Filed under:
|

Hi,

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("[email protected]","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>

© Stack Overflow or respective owner

Related posts about php

Related posts about html