Today's Posts Follow Us On Twitter! TFL Members on Twitter  
Forum search: Advanced Search  
Navigation
Marketplace
  Members Login:
Lost password?
  Forum Statistics:
Forum Members: 24,254
Total Threads: 80,792
Total Posts: 566,472
There are 2204 users currently browsing (tf).
 
  Our Partners:
 
  TalkFreelance     Marketplace     Looking For / Wanting to Sell Products     Other Digital Goods :

PHP Contact Script

Thread title: PHP Contact Script
Closed Thread  
Page 1 of 2 1 2 >
    Thread tools Search this thread Display Modes  
12-10-2006, 09:04 PM
#1
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old  PHP Contact Script

Hey, just made this for one of my sites, so I thought I'd let you guys use it.

PHP Code:
<?php
if (isset($_POST['submit'])) {
    
// Just make all the info good to work with
    
$to "admin@example.com";
    
$subject "Example.com Contact Form";
    
$name trim(stripslashes($_POST['name'])); 
    
$email trim(stripslashes($_POST['email'])); 
    
$message trim(stripslashes($_POST['message']));
    
$reason ucfirst($_POST['reason']);

    
// Check all fields for values
    
$error false;
    if (
trim($name) == "")
        
$error true;
    if (
trim($email) == "")
        
$error true;
    if (
trim($message) == "")
        
$error true;
    if (
$error == true) {
         echo 
"<span class=\"error\">One of the fields has been left blank. Please fill out all fields and try again.</span>\n";
    } else {
        
// Make the email all pretty
        
$body "Name: ".$name."\n";
        
$body .= "Email: ".$email."\n";
        
$body .= "Reason for Contact: ".$reason."\n";
        
$body .= "Message:\n".$message;
        
// Headers (thank you Patrick Paul)
        
$headers  "MIME-Version: 1.0\n";
        
$headers .= "Content-type: text/plain; charset=iso-8859-1\n";
        
$headers .= "X-Priority: 3\n";
        
$headers .= "X-MSMail-Priority: Normal\n";
        
$headers .= "X-Mailer: php\n";
        
$headers .= "From: ".$email."\n";
    

        
// Send Email
        
$sent mail($to$subject$body$headers);

        
// Print results
        
if ($sent) {
            echo 
"<p>Your email has been sent. Please allow time for a reply.</p>\n";
        } else {
            echo 
"<span class=\"error\">There has been an error while trying to send your email. Manually send an email to the webmaster to have this problem corrected.</span>\n";
        }
    }
}
?>
Code:
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
	<p>Name:</p>
	<input type="text" name="name" />
	<p>Email:</p>
	<input type="text" name="email" />
	<p>Reason for contact:</p>
	<select name="reason">
		<option name="1" value="support">Support</option>
		<option name="2" value="feedback">Feedback</option>
		<option name="3" value="feature request">Feature Request</option>
	</select>
	<p>Message:</p>
	<textarea name="message" rows="6" cols="40"></textarea>
	<p><input type="submit" name="submit" value="Submit Form" /></p>
</form>

12-10-2006, 09:09 PM
#2
Alex Eyre is offline Alex Eyre
Alex Eyre's Avatar
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
 
Posts: 1,132
iTrader: 5 / 100%
 

Alex Eyre is on a distinguished road

Send a message via MSN to Alex Eyre

  Old

thanks for the share, possible to add a file to send with the email?
-Alex.

12-10-2006, 09:10 PM
#3
Andrew R is offline Andrew R
Status: Request a custom title
Join date: Dec 2005
Location: Arizona
Expertise:
Software:
 
Posts: 5,200
iTrader: 17 / 95%
 

Andrew R is on a distinguished road

  Old

Eh, I'm too lazy..

12-10-2006, 09:16 PM
#4
Alex Eyre is offline Alex Eyre
Alex Eyre's Avatar
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
 
Posts: 1,132
iTrader: 5 / 100%
 

Alex Eyre is on a distinguished road

Send a message via MSN to Alex Eyre

  Old

ok, guess ill go goggle it :P
Thanks for whats there so far.
Alex.

12-10-2006, 09:31 PM
#5
Vlux is offline Vlux
Vlux's Avatar
Status: Sin Binner
Join date: Nov 2006
Location: England - Leeds
Expertise:
Software:
 
Posts: 476
iTrader: 0 / 0%
 

Vlux is on a distinguished road

Send a message via MSN to Vlux

  Old

Danke

12-10-2006, 09:52 PM
#6
Alex Eyre is offline Alex Eyre
Alex Eyre's Avatar
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
 
Posts: 1,132
iTrader: 5 / 100%
 

Alex Eyre is on a distinguished road

Send a message via MSN to Alex Eyre

  Old

Originally Posted by Vlux
Danke
Dankechen actually :P
I think :S

12-13-2006, 07:31 AM
#7
WardLarson is offline WardLarson
WardLarson's Avatar
Status: I love this place
Join date: Aug 2006
Location: Wenatchee, Washington
Expertise:
Software:
 
Posts: 662
iTrader: 0 / 0%
 

WardLarson is on a distinguished road

Send a message via AIM to WardLarson Send a message via MSN to WardLarson

  Old

Originally Posted by halotree06
Dankechen actually :P
I think :S

no. just.... no.

Danke = Thank you
Danke Shön = Thank you very much

and im not even German haha

12-13-2006, 11:31 AM
#8
sparckyz is offline sparckyz
sparckyz's Avatar
Status: Member
Join date: Nov 2006
Location: Nowhere
Expertise:
Software:
 
Posts: 192
iTrader: 0 / 0%
 

sparckyz is on a distinguished road

  Old

I got another one here if anyone's interested.
PHP Code:
<?php

/*
    Written by sparckyz
*/

//get variables
if($_POST['from'] && $_POST['sub'] && $_POST['mess'])
{

    
//your e-mail address
    
$To="some@address.com";

    
//check recipients e-mail address is formatted correctly
    
if(!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$",$To))
        die(
"please enter a valid 'to' address.");

    
//check senders e-mail address is formatted correctly
    
if(!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,6}$",$_POST['from']))
        die(
"please enter a valid 'from' address");

    
//simplify variables
    
$From=$_POST['from'];
    
$Subject=$_POST['sub'];
    
$Message=$_POST['mess'];

    
//mail the message
    
$Mail=mail($To,$Subject,$Message,"from: $From");

    
//check if message was sent
    
if($Mail)
    {
        echo 
"message sent successfully.";
    }
    else
    {
        echo 
"unable to deliver message.";
    }

}

?>


<!-- html form -->
<form name="mail" method="post" action="<?=$php_self ?>">

    from:<br> <input type="text" name="from"><br>
    subject:<br> <input type="text" name="sub"><br>
    message:<br> <textarea name="mess" wrap="virtual" cols="30" rows="4"></textarea><br>

    <input name="mail" type="submit" value="mail">

</form>
I wrote it a few days ago out of boredom, so might as well post it

12-13-2006, 06:15 PM
#9
Alex Eyre is offline Alex Eyre
Alex Eyre's Avatar
Status: Designer
Join date: Aug 2006
Location: Manchester
Expertise:
Software:
 
Posts: 1,132
iTrader: 5 / 100%
 

Alex Eyre is on a distinguished road

Send a message via MSN to Alex Eyre

  Old

Originally Posted by WardLarson
no. just.... no.

Danke = Thank you
Danke Shön = Thank you very much

and im not even German haha
and im taking GCSE next year.
Ich muB lerne Deutsch! aber ich habe viel zu machen!

*admits defeat* :P

Alex.

12-13-2006, 06:20 PM
#10
sparckyz is offline sparckyz
sparckyz's Avatar
Status: Member
Join date: Nov 2006
Location: Nowhere
Expertise:
Software:
 
Posts: 192
iTrader: 0 / 0%
 

sparckyz is on a distinguished road

  Old

patrickPaul, your clearly more of an elite coder than i am. So i bow down to your logic

Closed Thread  
Page 1 of 2 1 2 >


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

  Posting Rules  
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump:
 
  Contains New Posts Forum Contains New Posts   Contains No New Posts Forum Contains No New Posts   A Closed Forum Forum is Closed