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,471
There are 909 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-10-2006, 10:00 PM
#7
Dream is offline Dream
Dream's Avatar
Status: Lewis Ainslie
Join date: Dec 2005
Location: UK, England.
Expertise:
Software:
 
Posts: 1,630
iTrader: 15 / 100%
 

Dream is on a distinguished road

Send a message via MSN to Dream

  Old

Thanks bud,

Ill use it!

12-12-2006, 10:25 PM
#8
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

I will post another Uplaod script tommorow, that I made to suit my concept, might help someone.
Alex.

12-12-2006, 11:12 PM
#9
patrickPaul is offline patrickPaul
Status:
Join date: Dec 2004
Location: California, US
Expertise:
Software:
 
Posts: 406
iTrader: 1 / 100%
 

patrickPaul is on a distinguished road

Send a message via AIM to patrickPaul Send a message via MSN to patrickPaul Send a message via Yahoo to patrickPaul

  Old

Just so you know you might want to add some headers so it is less likely to be flagged as spam...

PHP Code:
    $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: Your Site <noreply@yoursite.com>\n";
    
    
mail($to,$subject$body,$headers); 

Add the $headers section and change the mail() function to the one above.

Regards,
Patrick

12-13-2006, 05:17 AM
#10
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

Ah, can't believe I forgot about headers. :\

Edited in first post.

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