Hi,

I have a contact form which is laid out like the following;

<form id="form1" name="form1" method="post" action="send.php">
        <table width="362" border="0" align="center" class="tbltxt">
          <tr>
            <td height="30" colspan="2" style="color:#174AA8; text-decoration:underline;"><b>Send us a message!</b></td>
          </tr>
          <tr>
            <td width="95" height="30"><label for="Name">Name</label></td>
            <td width="257"height="30"><input name="Name" type="text" id="Name" style="width:200px;" /></td>
          </tr>
          <tr>
            <td height="30"><label for="Subject">Subject</label></td>
            <td height="30"><select name="Subject" id="Subject" style="width:200px;">
              <option value="Technical issue">Technical issue</option>
              <option value="Rates">Rates</option>
              <option value="Other">Other</option>
            </select></td>
          </tr>
          <tr>
            <td height="30">Email address</td>
            <td height="30"><input name="Email" type="text" id="Email" style="width:200px;" /></td>
          </tr>
          <tr>
            <td valign="top">Message</td>
            <td><label for="Message"></label>
            <textarea name="Message" id="Message" rows="5" style="width:200px;"></textarea></td>
          </tr>
          <tr>
            <td height="30">&nbsp;</td>
            <td height="30"><input type="submit" name="send" id="send" value="Send now" />
            <input type="reset" name="Reset" id="button" value="Clear form" /></td>
          </tr>
        </table>
        <p>&nbsp;</p>
      </form>

After the user presses the 'Send now' button instead of it redirecting off to another page I want some text to appear below the table stating that the message has been sent.


Any ideas how I can achieve this?

Thanks :)

Try this

<?php
 if(isset($_POST["send"]))
 {
     <-- Your Mail Code -->
     
     $msg="Mail has been sent successfully!";
 }

     <form id="form1" name="form1" method="post" action="">
    <table width="362" border="0" align="center" class="tbltxt">
    <?php
        if(isset($msg) && $msg!="")
        {
    ?>
     <tr>
    <td height="30" colspan="2" style="color:#ff0000;"><?php echo $msg; ?></td>
    </tr>
    <?php
       }
    ?>
    <tr>
    <td height="30" colspan="2" style="color:#174AA8; text-decoration:underline;"><b>Send us a message!</b></td>
    </tr>
    <tr>
    <td width="95" height="30"><label for="Name">Name</label></td>
    <td width="257"height="30"><input name="Name" type="text" id="Name" style="width:200px;" /></td>
    </tr>
    <tr>
    <td height="30"><label for="Subject">Subject</label></td>
    <td height="30"><select name="Subject" id="Subject" style="width:200px;">
    <option value="Technical issue">Technical issue</option>
    <option value="Rates">Rates</option>
    <option value="Other">Other</option>
    </select></td>
    </tr>
    <tr>
    <td height="30">Email address</td>
    <td height="30"><input name="Email" type="text" id="Email" style="width:200px;" /></td>
    </tr>
    <tr>
    <td valign="top">Message</td>
    <td><label for="Message"></label>
    <textarea name="Message" id="Message" rows="5" style="width:200px;"></textarea></td>
    </tr>
    <tr>
    <td height="30">&nbsp;</td>
    <td height="30"><input type="submit" name="send" id="send" value="Send now" />
    <input type="reset" name="Reset" id="button" value="Clear form" /></td>
    </tr>
    </table>
    <p>&nbsp;</p>
    </form>

I have modified it.
If you don't have header then each time user press F5 mail will be sent.
Its always good practice to have header after form submission.

<?php
 if(isset($_POST["send"]))
 {
    // php mail sending code
	header("location:contactus.php?succ");
	exit;    
 }
?>
     <form id="form1" name="form1" method="post" action="">
    <table width="362" border="0" align="center" class="tbltxt">   
    <tr>
    <td height="30" colspan="2" style="color:#174AA8; text-decoration:underline;"><b>Send us a message!</b></td>
    </tr>
     <?php
        if(isset($_GET['succ']))
        {
    ?>
     <tr>
    <td height="30" colspan="2" style="color:#ff0000;">Mail is successfully sent.</td>
    </tr>
    <?php
       }
    ?>
    <tr>
    <td width="95" height="30"><label for="Name">Name</label></td>
    <td width="257"height="30"><input name="Name" type="text" id="Name" style="width:200px;" /></td>
    </tr>
    <tr>
    <td height="30"><label for="Subject">Subject</label></td>
    <td height="30"><select name="Subject" id="Subject" style="width:200px;">
    <option value="Technical issue">Technical issue</option>
    <option value="Rates">Rates</option>
    <option value="Other">Other</option>
    </select></td>
    </tr>
    <tr>
    <td height="30">Email address</td>
    <td height="30"><input name="Email" type="text" id="Email" style="width:200px;" /></td>
    </tr>
    <tr>
    <td valign="top">Message</td>
    <td><label for="Message"></label>
    <textarea name="Message" id="Message" rows="5" style="width:200px;"></textarea></td>
    </tr>
    <tr>
    <td height="30">&nbsp;</td>
    <td height="30"><input type="submit" name="send" id="send" value="Send now" />
    <input type="reset" name="Reset" id="button" value="Clear form" /></td>
    </tr>
    </table>
    <p>&nbsp;</p>
    </form>
commented: Useful post +4

Thanks for your help, I kind of understand what is going on here with 'vibhadevits' post. Would I need to change my php mail code so that I can get this sent to an email address?

No ben,
You don't have to change your php mail code.
If you are not getting emails post your code here for checking.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.