View Single Post
05-25-2008, 09:05 PM
#28
thebluenote is offline thebluenote
Status: Junior Member
Join date: May 2008
Location: NY
Expertise:
Software:
 
Posts: 39
iTrader: 0 / 0%
 

thebluenote is on a distinguished road

Send a message via AIM to thebluenote

  Old

Originally Posted by ncmason View Post
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);


// 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>Provide a name please!</p></span>"
    
    }
    
    if(
$subject == "") { 
    
    echo 
"<span class=\"text\"<p>Enter a subject!</p></span>"
    
    } else {
    
    if(
$email == "") { 
    
    echo 
"<span class=\"text\"<p>You must enter your email!</p></span>"
    
    } else { 
    
    
mail(); 
    
    } }
?>
My 3 problems now are:

1. Getting the success page to come up only upon valid completion of the forms.

2. Only send an email if the forms are complete.

3. When the user sees the "go back and try it again" page, I want it to automatically go back to the form.

Thanks,
Mason

1. Just put a redirect under the mail function to a page that you make that says success.

2. Use the elseifs like Andrew said

3. Just use one echo to say "please enter information for all fields" if the email doesn't go through.