TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 05-26-2008, 02:38 AM   #1 (permalink)
The Visitor
 
Join Date: May 2008
Posts: 3
Thanks: 0
ncmason is on a distinguished road
Default PHP Contact Form - 2 Questions

I have a few questions about this contact form I'm making in PHP:

1. How can I use the "header" method when I have HTML tags?

2. I want my form to only send an email if all the forms are filled out. I've heard about using "elseif" but I don't know how to use it with 3 variables.

Here's the code (there is CAPTCHA code, but I'm not showing it for security purposes)

PHP Code:
<?php
// Pick up the form data and assign it to variables

    
$name $_POST['name'];
    
$email $_POST['email'];
    
$url $_POST['url'];
    
$comments $_POST['comments'];

// Build the email 

    
$to 'mason@masonsklut.com';
    
$subject "Comment";
    
$message "Name: $name"\n"  "E-mail: $email"\n" "URL: $url"\n" "Comment: $comments";
    
$headers "From: $name"\r\n" .
        
"Reply-To: $email";

// Send the mail using PHPs mail() function

    
mail($to$subject$message$headers);

// Redirect
    
    
header ('Location: http://masonsklut.com/test/success.html');
    
// Mail header removal

    
function remove_headers($string) { 
      
$headers = array(
        
"/to\:/i",
        
"/from\:/i",
        
"/bcc\:/i",
        
"/cc\:/i",
        
"/Content\-Transfer\-Encoding\:/i",
        
"/Content\-Type\:/i",
        
"/Mime\-Version\:/i" 
      
); 
      
$string preg_replace($headers''$string);
      return 
strip_tags($string);
    } 

// Pick up the cleaned form data

    
$name remove_headers($_POST['name']);
    
$email remove_headers($_POST['email']);
    
$url remove_headers($_POST['url']);
    
$comments remove_headers($_POST['comments']);
    
// Field verification

    
if($name == "") { 
    
    echo 
"<span class=\"text\"><p>Please enter required fields!</p></span>"
    
    if(
$subject == "")
    
    echo 
"<span class=\"text\"><p>Please enter required fields!</p></span>";
    
    if(
$email =="")
    
    echo 
"<span class=\"text\"><p>Please enter required fields!</p></span>";
    
    
mail(); 
    
    }
?>
ncmason is offline  
Reply With Quote
 



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

Advanced Search
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

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


All times are GMT. The time now is 03:00 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design