NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming
Reload this Page Need some help with a contect form

Programming PHP, Perl, Ruby on Rails, AJAX, HTML, XHTML, CSS, JavaScript, MySQL and any other coding topics.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 12-30-2006, 06:21 PM THREAD STARTER               #1 (permalink)
Senior Member
Join Date: Nov 2003
Location: Florida
Posts: 2,026
slipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to behold
 



Need some help with a contect form


Hey everyone.

I am working on a site and I need to get a contact form working. It sounds dumb but I have it on the page, but what do I need to do to get it to work. Its done in dreamweaver
????: NamePros.com http://www.namepros.com/programming/275012-need-some-help-with-contect-form.html

</style>
<form name="form1" method="post" action="">
<table width="450" border="0">
<tr>
<td width="73">Name</td>
<td width="367"><label>
<input name="name" type="text" id="name">
</label></td>
</tr>
<tr>
<td>Email</td>
<td><label>
<input name="email" type="text" id="email">
</label></td>
</tr>
<tr>
<td>Comment</td>
<td><label>
<textarea name="comment" id="comment"></textarea>
</label></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label>
<input name="Submit" type="submit" class="button" value="Send">
<input name="Submit2" type="reset" class="button" value="Clear">
</label></td>
</tr>
</table>
</form>
slipondajimmy is offline  
Old 12-30-2006, 06:48 PM   #2 (permalink)
Munky Designs
Join Date: May 2005
Posts: 996
Albino is a jewel in the roughAlbino is a jewel in the roughAlbino is a jewel in the rough
 



you need to use a language like php or javascript to get it to grab the variables
Albino is offline  
Old 12-30-2006, 08:01 PM THREAD STARTER               #3 (permalink)
Senior Member
Join Date: Nov 2003
Location: Florida
Posts: 2,026
slipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to behold
 



any ideas on a easy way to get it done?
slipondajimmy is offline  
Old 12-30-2006, 08:27 PM   #4 (permalink)
Senior Member
Join Date: May 2005
Location: Ontario Canada
Posts: 3,088
unknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to beholdunknowngiver is a splendid one to behold
 


Diabetes
hm first of all do you have PHP on your server?
add me on msn i will help u make 1 in php [mzubair01@hotmail.com]
unknowngiver is offline  
Old 12-30-2006, 08:31 PM THREAD STARTER               #5 (permalink)
Senior Member
Join Date: Nov 2003
Location: Florida
Posts: 2,026
slipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to behold
 



I have PHP on my server. I found a script I can use and it will send mail... but no subject or message. And it sends from my server and not a email I specify. Maybe there is something missing

<html>
<head><title>PHP Mail Sender</title></head>
<body>
<?php

/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$name = $HTTTP_POST_VARS ['name'];
$email = $HTTP_POST_VARS['email'];
$comment = $HTTP_POST_VARS['comment'];


/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "") {
????: NamePros.com http://www.namepros.com/showthread.php?t=275012
echo "<h4>No subject</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}

/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
elseif (mail($email,$subject,$message)) {
echo "<h4>Thank you for sending email</h4>";
} else {
echo "<h4>Can't send email to $email</h4>";
}
?>
</body>
</html>
slipondajimmy is offline  
Old 12-30-2006, 08:49 PM   #6 (permalink)
NamePros Regular
Join Date: Feb 2006
Posts: 584
jerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to all
 



This setting in phpini needs to be changed - sendmail_from
Changing it changes what address appears in the from address.

You need to have a form in order to send mail.
If you don't want to, edit :

$name = $HTTTP_POST_VARS ['name'];
$email = $HTTP_POST_VARS['email'];
$comment = $HTTP_POST_VARS['comment'];

to

$subject = " - Subject - ";
$email = " - To Email - ";
$message = " - To Message - ";

Edit the content inside.
jerometan is offline  
Old 12-30-2006, 09:32 PM THREAD STARTER               #7 (permalink)
Senior Member
Join Date: Nov 2003
Location: Florida
Posts: 2,026
slipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to behold
 



I think I have been working on this to much tonight . I need to give it a rest and try again tommorow.

I just need this http://www.kitcar.ws/test.html (just a test) To function.

Like I said I can get it to send, but with no message and with a server email.

So if anyone can help it would be great
slipondajimmy is offline  
Old 12-30-2006, 11:01 PM   #8 (permalink)
NamePros Regular
Join Date: Feb 2006
Posts: 584
jerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to all
 



Sorry, missing out on the form posted.

Heres a fix :

Code:
<form name="form1" method="post" action="">
<table width="450" border="0">
<tr>
<td width="73">Name</td>
<td width="367"><label>
<input name="name" type="text" id="name">
</label></td>
</tr>
<tr>
<td>Email</td>
<td><label>
<input name="email" type="text" id="email">
</label></td>
</tr>
<tr>
<td>Subject</td>
<td><label>
<input name="subject" type="text" id="subject">
</label></td>
</tr>
<tr>
<td>Message</td>
<td><label>
<textarea name="message" id="message"></textarea>
</label></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><label>
<input name="Submit" type="submit" class="button" value="Send">
<input name="Submit2" type="reset" class="button" value="Clear">
</label></td>
</tr>
</table>
</form>
For the PHP Code :

Code:
/* All form fields are automatically passed to the PHP script through the array $HTTP_POST_VARS. */
$name = $HTTP_POST_VARS ['name'];
$email = $HTTP_POST_VARS['email'];
$message = $HTTP_POST_VARS['message'];
$subject = $HTTP_POST_VARS['subject'];


/* PHP form validation: the script checks that the Email field contains a valid email address and the Subject field isn't empty. preg_match performs a regular expression match. It's a very powerful PHP function to validate form fields and other strings - see PHP manual for details. */
if (!preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/", $email)) {
echo "<h4>Invalid email address</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
} elseif ($subject == "") {
echo "<h4>No subject</h4>";
echo "<a href='javascript:history.back(1);'>Back</a>";
}

/* Sends the mail and outputs the "Thank you" string if the mail is successfully sent, or the error string otherwise. */
elseif (mail($email,$subject,$message)) {
echo "<h4>Thank you for sending email</h4>";
} else {
echo "<h4>Can't send email to $email</h4>";
}
?>
</body>
</html>
jerometan is offline  
Old 12-31-2006, 09:03 AM THREAD STARTER               #9 (permalink)
Senior Member
Join Date: Nov 2003
Location: Florida
Posts: 2,026
slipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to behold
 



Now im getting this

Method Not Allowed
The requested method POST is not allowed for the URL XXX/XXX.
slipondajimmy is offline  
Old 12-31-2006, 09:50 AM   #10 (permalink)
Domains my Dominion
 
sdsinc's Avatar
Join Date: Aug 2005
Location: Web 1.0
Posts: 9,552
sdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatnesssdsinc Has achieved greatness
 


Third World Education Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Find Marrow Donors! Animal Rescue Animal Cruelty AIDS/HIV Animal Rescue Wildlife Breast Cancer Animal Rescue Wildlife
Originally Posted by slipondajimmy
Now im getting this

Method Not Allowed
The requested method POST is not allowed for the URL XXX/XXX.
Maybe you should rename the ext from .html to .php

Also, if you are using third-party code make sure you understand the risk of E-mail injection:
http://www.securephpwiki.com/index.php/Email_Injection
__________________
NameNewsletter.com - free lists of available domain names
ZoneFiles.net (beta) - ccTLD and gTLD droplists
sdsinc is offline  
Old 12-31-2006, 09:56 AM   #11 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
jerometan, HTTP_POST_VARS? That was depreciated for $_POST autoglobal in php 4.1.

Also as has been said, that code is open to header injections.
Matthew. is offline  
Old 12-31-2006, 10:11 AM THREAD STARTER               #12 (permalink)
Senior Member
Join Date: Nov 2003
Location: Florida
Posts: 2,026
slipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to behold
 



Thanks for everyones help. So does anyone have any idea of a simple script I can use. IM putting a site together as a favor to someone and dont really want to spend any money on it.

This should have been simple and done by now..hhaha
slipondajimmy is offline  
Old 12-31-2006, 10:44 AM   #13 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
This is my adapted version slipondajimmy, use it if you wish.

PHP Code:
<?php
define
('_sendto''youraddress@email.com');

if( 
$_SERVER['REQUEST_METHOD'] == 'POST' )
{
     foreach(
$_POST as $key => $value)
    {
         
$_POST[$key] = addslashes(stripslashes($value));
    }
    
    
     if( !
strlen($_POST['e_name']) > )
????: NamePros.com http://www.namepros.com/showthread.php?t=275012
     {
          
$error[] = 'No name given';
     }
     
     if( !
strlen($_POST['e_from']) > )
     {
          
$error[] = 'You did not supply your email';
     }
     else
     {

        if (!
preg_match("/\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*/"$_POST['e_from'])) 
        {
             
$error[] = 'The email given was invalid!';
        }
    }
     
     if( !
strlen($_POST['e_message']) > )
     {
          
$error[] = 'The message was left blank';
     }
     
     if( 
count$error ) > )
????: NamePros.com http://www.namepros.com/showthread.php?t=275012
     {
          foreach(
$error as $value)
          {
               echo 
$value '<br />';
          }
     }
     else
     {
          
$pattern "/(content-type|bcc:|cc:)/i";
        
        if (
preg_match($pattern$_POST['e_name']) || preg_match($pattern$_POST['e_from']) || preg_match($pattern$_POST['e_message'])) 
        {
             die(
'No injections please');
        }
        else
        {
         
              if(
mail(_sendto'Message from contact form'$_POST['e_message'], "From: <{$_POST['e_from']}{$_POST['e_from']}\r\n
                                                                                  Reply-To: 
{$_POST['e_from']}"))
              {
                   echo 
'The message was sent!';
              }
              else
              {
                   
trigger_error('The email could not be sent!'E_USER_WARNING);
              }
         }
     }
}
else
{
     
?>
     <form action="?" method="post">
     Name:     <input type="text" name="e_name" value="" /><br />
     Email:     <input type="text" name="e_from" value="" /><br />
     Message:<textarea name="e_message"></textarea>
             <input type="submit" name="submit" value="Send" />
     </form>
     
     <?php
}
?>
Untested, should work.
Last edited by Matthew.; 01-01-2007 at 07:31 AM.
Matthew. is offline  
Old 12-31-2006, 11:28 AM THREAD STARTER               #14 (permalink)
Senior Member
Join Date: Nov 2003
Location: Florida
Posts: 2,026
slipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to behold
 



thanks a bunch. Im still getting this though. I must be missing something

Method Not Allowed
The requested method POST is not allowed for the URL
slipondajimmy is offline  
Old 12-31-2006, 12:10 PM   #15 (permalink)
Senior Member
Join Date: Dec 2006
Location: England
Posts: 1,568
Matthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud ofMatthew. has much to be proud of
 


Adoption Breast Cancer Breast Cancer Cancer Survivorship
I have only ever known that message to appear as sdsinc said when your exstension is .html or .htm

Unless you have created a handler so php will parse in html files (not advised) your file extension must be .php
Matthew. is offline  
Old 12-31-2006, 12:52 PM   #16 (permalink)
NamePros Regular
Join Date: Feb 2006
Posts: 584
jerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to alljerometan is a name known to all
 



Originally Posted by Matthew.
jerometan, HTTP_POST_VARS? That was depreciated for $_POST autoglobal in php 4.1.
????: NamePros.com http://www.namepros.com/showthread.php?t=275012

Also as has been said, that code is open to header injections.
I know the code is not secure, and HTTP_POST_VARS shouldnt be used.

However, he asked for his contact form to be fixed with functionality.

So I didn't make much changes to the script (how do i know what PHP version he has).

Rename the file (the one Matthew provided) to *.php.
jerometan is offline  
Old 01-01-2007, 11:08 AM THREAD STARTER               #17 (permalink)
Senior Member
Join Date: Nov 2003
Location: Florida
Posts: 2,026
slipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to beholdslipondajimmy is a splendid one to behold
 



Thanks everyone. Its working fine now
slipondajimmy is offline  
Closed Thread


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


Liquid Web Smart Servers  
All times are GMT -7. The time now is 07:12 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger