Thread: else problem
View Single Post
Old 11-11-2008, 07:58 PM   #11 (permalink)
Runar
The Contributor
 
Runar's Avatar
 
Join Date: Nov 2008
Location: Norway
Posts: 58
Thanks: 20
Runar is on a distinguished road
Default

Try this code. Either was my explanation poor, or you misunderstood what I meant about using !empty(). Anyway, try this code and let me know what you get:

PHP Code:
<?php

// Display all errors
ini_set'display_errors''yes' );

// Post data
$name      $_POST['name'];
$phone     $_POST['phone'];
$website   $_POST['website'];
$email     $_POST['email'];
$message   $_POST['message'];

// Define some mail variables
$recipient "info@url.com";
$subject   'Client Request';
$header    'From: ' .  $name ' <' $email '>' "\r\n";
$body      'Name: ' $name "\n\nPhone: " $phone "\n\nWebsite: " $website "\n\nEmail: " $email "\n\nMessage: " $message;

// Check that all required fields (name, phone, email, message) are set
if( !empty( $name ) && !empty( $phone ) && !empty( $email ) && !empty( $message ) )
{
    
// Attempt to send mail
    
if( mail$recipient$subject$body$header ) )
    {
        
header'Location: /thanks.php' );
    }
    
    
// Failed
    
else
    {
        
header'Location: /mailfail.php' );
    }
}

// One or more of the required fields were missing, redirect to error page
else
{
    
header'Location: /error.php' );
}

?>
Send a message via MSN to Runar
Runar is offline  
Reply With Quote