Current location: Hot Scripts Forums » Programming Languages » PHP » php email form?


php email form?

Reply
  #1 (permalink)  
Old 06-26-06, 07:58 AM
godonholiday godonholiday is offline
Newbie Coder
 
Join Date: Feb 2005
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
php email form?

i have a form that saves the info to my sqldatabase, this all works fine, but i would like to have the information sent in an email to my email address so i have two copies of it.

can anyone have a look at my code and see if i can add some code to it so that it sends an email on submition. thanks

PHP Code:

<form action="<?php echo $editFormAction?>" method="post" name="form1" onSubmit="MM_validateForm('name','','R','email','','NisEmail','message','','R');return document.MM_returnValue">

      <table width="435"  border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
              <tr align="left" valign="top">
                <td width="232"><table width="175"  border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td height="18" align="left" valign="top" class="style6"><strong>Name:</strong></td>
                    </tr>
                    <tr>
                      <td height="31" align="left" valign="top" class="style6"><input name="name" type="text" id="name" style="width:175px; height:18px; font-family:tahoma; font-size:11px;"></td>
                    </tr>
                    <tr>
                      <td height="18" align="left" valign="top" class="style6"><strong>E-mail:</strong></td>
                    </tr>
                    <tr>
                      <td height="31" align="left" valign="top" class="style6"><input name="email" type="text" id="email" style="width:175px; height:18px; font-family:tahoma; font-size:11px;"></td>
                    </tr>
                    <tr>
                      <td height="18" align="left" valign="top" class="style6"><strong>Tel:</strong></td>
                    </tr>
                    <tr>
                      <td align="left" valign="top" class="style6"><input name="tel" type="text" id="tel" style="width:175px; height:18px; font-family:tahoma; font-size:11px "></td>
                    </tr>
                </table></td>
                <td><table width="175"  border="0" cellspacing="0" cellpadding="0">
                    <tr>
                      <td height="17" align="left" valign="top" class="style6"><strong>Message:</strong></td>
                    </tr>
                    <tr>
                      <td height="27" align="left" valign="top" class="style6"><textarea name="message" cols="10" rows="10" id="message" style="width:203px; height:118px; font-family:tahoma; font-size:11px; overflow:auto"></textarea></td>
                    </tr>
                </table></td>
              </tr>
          </table></td>
        </tr>
        <tr>
          <td height="23" align="right" valign="bottom">&nbsp;&nbsp;&nbsp;
            <input name="submit" type="submit" value="Send"></td>
        </tr>
      </table>
      <input type="hidden" name="MM_insert" value="form1">
    </form>
Reply With Quote
  #2 (permalink)  
Old 06-26-06, 09:23 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
PHP Code:



$youremail 
'example@example.com';
$subject 'Contact form';

if (isset(
$_POST))
{
      
$str '';
       
      foreach (
$_POST as $key => $val)
      {
           
$str .= ucfirst($key) .': '$val ."\n";
      }

      
mail($youremail$subject$str'From: "'$yourmail .'" <'$yourmail .'>');

Untested but should work.
Reply With Quote
  #3 (permalink)  
Old 06-26-06, 09:46 AM
godonholiday godonholiday is offline
Newbie Coder
 
Join Date: Feb 2005
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
cool thanks for that, where abouts in my code should that go? and will that get the email, tel, and comment aswell and put it in the email?
cheers
Reply With Quote
  #4 (permalink)  
Old 06-26-06, 09:55 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
This code should be placed in whatever <?php echo $editFormAction; ?> outputs.
And yes, every POST data that is sent to the page will be submitted.
Reply With Quote
  #5 (permalink)  
Old 06-27-06, 07:45 AM
godonholiday godonholiday is offline
Newbie Coder
 
Join Date: Feb 2005
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
sorry do you mean that the code goes inside this code <?php echo $editFormAction; ?>

or anywhere after it?

thansk
Reply With Quote
  #6 (permalink)  
Old 06-27-06, 07:58 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
When you see the form in your browser, what does it say instead of "<?php echo $editFormAction; ?>"? There should be a filename. Add the code above in this page.
Reply With Quote
  #7 (permalink)  
Old 06-27-06, 08:24 AM
godonholiday godonholiday is offline
Newbie Coder
 
Join Date: Feb 2005
Posts: 64
Thanks: 0
Thanked 0 Times in 0 Posts
Quote:
Originally Posted by nico_swd
When you see the form in your browser, what does it say instead of "<?php echo $editFormAction; ?>"? There should be a filename. Add the code above in this page.
it doesnt say anything instead of that, it says that. my coade is above. thats all i have to work with. im not sure what you mean by a filename?

thanks again
Reply With Quote
  #8 (permalink)  
Old 06-27-06, 08:33 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
The form is submitted to a page. In your case in the code above the form points to a php variable.

PHP Code:

<form action="<?php echo $editFormAction?>"
$editFormAction should contain the filename to which the form is submitted. You will see what the variable contains when you "echo" it. Go to the page on your server where this form here is and have a look at the source code. What does it say where the <?php echo $editFormAction; ?> is?
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Tute: Create Email based Contact Form Grabber PHP 3 05-31-06 03:11 AM
Easy to set up Email Form for novice muddle Script Requests 0 04-25-06 09:48 AM
php form script to more then one email? burnttoast PHP 9 07-15-05 09:57 AM
Sending form data + attatchments in email php-learner PHP 2 02-14-04 12:18 AM


All times are GMT -5. The time now is 07:18 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.