0

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 :)

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by vibhaJ
0

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>

Edited by karthik_ppts: n/a

1

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>
Votes + Comments
Useful post
0

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?

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.