Jump to content

Recommended Posts

I am wondering how to have form results submit to my e-mail. Below is my code, if anyone could tell me where to insert what I need, I would definitely appreciate it!

 

<form action="" method="post" name="form1">

<table width="443" border="0">

<tr>

<td width="131"><span class="style14">Your Name: </span></td>

<td width="246"><span class="style14">

<input type="text" name="textfield">

</span></td>

</tr>

<tr>

<td><span class="style14">Recipient Name: </span></td>

<td><span class="style14">

<input type="text" name="textfield">

</span></td>

</tr>

<tr>

<td><span class="style14">Your E-mail:</span></td>

<td><span class="style14">

<input type="text" name="textfield">

</span></td>

</tr>

<tr>

<td><span class="style14">Subject:</span></td>

<td><span class="style14">

<input type="text" name="textfield">

</span></td>

</tr>

<tr>

<td><span class="style14">Message:</span></td>

<td><p class="style14">

<textarea name="textarea"></textarea>

</p>

</td>

</tr>

<tr>

<td> </td>

<td><input type="submit" name="Submit" value="Submit">

<input type="reset" name="Reset" value="Reset"></td>

</tr>

</table>

</form>

Link to comment
https://forums.phpfreaks.com/topic/2405-forms/
Share on other sites

I am wondering how to have form results submit to my e-mail. Below is my code, if anyone could tell me where to insert what I need, I would definitely appreciate it!

 

<form action="" method="post" name="form1">

          <table width="443" border="0">

                        <tr>

                          <td width="131"><span class="style14">Your Name: </span></td>

                          <td width="246"><span class="style14">

                            <input type="text" name="textfield">

                          </span></td>

                        </tr>

                        <tr>

                          <td><span class="style14">Recipient Name: </span></td>

                          <td><span class="style14">

                            <input type="text" name="textfield">

                          </span></td>

                        </tr>

                        <tr>

                          <td><span class="style14">Your E-mail:</span></td>

                          <td><span class="style14">

                            <input type="text" name="textfield">

                          </span></td>

                        </tr>

                        <tr>

                          <td><span class="style14">Subject:</span></td>

                          <td><span class="style14">

                            <input type="text" name="textfield">

                          </span></td>

                        </tr>

                        <tr>

                          <td><span class="style14">Message:</span></td>

                          <td><p class="style14">

                            <textarea name="textarea"></textarea>

</p>

                          </td>

                        </tr>

                        <tr>

                          <td> </td>

                          <td><input type="submit" name="Submit" value="Submit">

                          <input type="reset" name="Reset" value="Reset"></td>

                        </tr>

                      </table>

          </form>

254127[/snapback]

 

First, you need to change the "name" property of your textboxes to something that describes what is in them. So, if the first textbox is "name", you will need to change "name = 'textfield'" to "name='name'". Do this for the rest of the form.

 

Then you are going to start off by setting up the process part of the page.

 

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?php

[/span][span style=\"color:#007700\"]if(isset([/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'Submit\'[/span][span style=\"color:#007700\"]]))

{

     [/span][span style=\"color:#FF8000\"]//Enter form processing here

[/span][span style=\"color:#007700\"]}

else

{

     [/span][span style=\"color:#FF8000\"]//Your form could go here so it doesn\'t show up when you submit it.

[/span][span style=\"color:#007700\"]}

[/span][span style=\"color:#0000BB\"]?>[/span]

[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

 

So after this, we will need to get all the values of the textboxes on your form.

 

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?php

[/span][span style=\"color:#007700\"]if(isset([/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'Submit\'[/span][span style=\"color:#007700\"]]))

{

     [/span][span style=\"color:#0000BB\"]$name [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'name\'[/span][span style=\"color:#007700\"]];

     [/span][span style=\"color:#0000BB\"]$email [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#0000BB\"]$_POST[/span][span style=\"color:#007700\"][[/span][span style=\"color:#DD0000\"]\'email\'[/span][span style=\"color:#007700\"]];

     [/span][span style=\"color:#FF8000\"]//etc... You get the point.

[/span][span style=\"color:#007700\"]}

else

{

    [/span][span style=\"color:#FF8000\"]//form

[/span][span style=\"color:#007700\"]}

[/span][span style=\"color:#0000BB\"]?>[/span]

[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

 

After you collect all of your data, go ahead and do any error checking you want on it. (Check if it is empty, correct, etc).

 

Then comes the mail part.

 

[!--PHP-Head--][div class=\'phptop\']PHP[/div][div class=\'phpmain\'][!--PHP-EHead--][span style=\"color:#0000BB\"]<?php

[/span][span style=\"color:#007700\"]...

     [/span][span style=\"color:#FF8000\"]//the mail function

     [/span][span style=\"color:#0000BB\"]$to [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"\" [/span][span style=\"color:#FF8000\"]//The person you are sending it to

     [/span][span style=\"color:#0000BB\"]$subject [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"\" [/span][span style=\"color:#FF8000\"]//The subject of the email

     [/span][span style=\"color:#0000BB\"]$message [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"\" [/span][span style=\"color:#FF8000\"]//The message you want to appear in the body of the email

     [/span][span style=\"color:#0000BB\"]$email [/span][span style=\"color:#007700\"]= [/span][span style=\"color:#DD0000\"]\"\" [/span][span style=\"color:#FF8000\"]//The person email address who is sending email

 

     [/span][span style=\"color:#0000BB\"]mail[/span][span style=\"color:#007700\"]([/span][span style=\"color:#0000BB\"]$to[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$subject[/span][span style=\"color:#007700\"], [/span][span style=\"color:#0000BB\"]$message[/span][span style=\"color:#007700\"], [/span][span style=\"color:#DD0000\"]\"FROM: $email\"[/span][span style=\"color:#007700\"]);

...

[/span][span style=\"color:#0000BB\"]?>[/span]

[/span][!--PHP-Foot--][/div][!--PHP-EFoot--]

 

The mail part goes in the processing part of the script.

 

Jeremy

Link to comment
https://forums.phpfreaks.com/topic/2405-forms/#findComment-7916
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.