Jump to content

form submission $_Post


acctman
 Share

Recommended Posts

can someone visually just read through my code and let me know if this looks like it'll work? I'm not getting any errors in my IDE so now I want to double check the structure

 

 

<?php
require_once '/usr/local/cpanel/3rdparty/lib/php/Mail.php';

$db_server = 'localhost';
$db_user = '-----';
$db_pass = '-----';

$dbc = mysql_connect ($db_server, $db_user, $db_pass);
if (!$dbc) { 
    die(mysql_error());
    header ('Location: /contact');
    exit;
}

if ($_POST['contactsent'] != 'yes') {
    header ('Location: /contact');
    exit;
    
} else {
    
if (is_array($_POST)) {
        foreach ($_POST as $key => $value) {
            $_POST[$key] = mysql_real_escape_string(stripslashes($value));
        }
    }

    $RequestType      = $_POST["RequestType"];
    $ConsumerBusiness = $_POST["ConsumerBusiness"];
    $GlobalLocation   = $_POST["GlobalLocation"];
    $FirstName        = strtolower(str_replace("'","''",$_POST["FirstName"]));
    $FirstName        = strtoupper(substr($FirstName,0,1)).substr($FirstName,1);
    $LastName         = strtolower(str_replace("'","''",$_POST["LastName"]));
    $LastName         = strtoupper(substr($LastName,0,1)).substr($LastName,1);
    $Email            = strtolower(str_replace("'","''",$_POST["Email"]));
    $Title            = strtolower(str_replace("'","''",$_POST["Title"]));
    $Title            = strtoupper(substr($Title,0,1)).substr($Title,1);
    $Company          = strtolower(str_replace("'","''",$_POST["Company"]));
    $Company          = strtoupper(substr($Company,0,1)).substr($Company,1);
    $Address          = strtolower(str_replace("'","''",$_POST["Address"]));
    $Address          = strtoupper(substr($Address,0,1)).substr($Address,1);
    $City             = strtolower(str_replace("'","''",$_POST["City"]));
    $City             = strtoupper(substr($City,0,1)).substr($City,1);
    $State            = $_POST["State"];
    $Zip              = $_POST["Zip"];
    $Phone            = $_POST["Phone"];
    $F              = $_POST["F"];
    $ProductDesc      = $_POST["ProductDesc"];
    $Comment          = $_POST["Comment"];

    if ($GlobalLocation == "Canada"):
        $SendTo="canadainfo@------.com";
    elseif ($GlobalLocation == "Central America"): 
        $SendTo="customer.service@------.com.pa";
    elseif ($GlobalLocation == "Europe"):
        $SendTo="marketing@-----.uk";
    elseif ($GlobalLocation == "Mexico"):
        $SendTo="ventas@------.com.mx";
    else:
        $SendTo="info@------.com";
    endif;

function dbSet($fields, $source = array()) {
    $set='';
    if (!source) $source = &$_POST;
    foreach ($fields as $field) {
        if (isset($source[$field])) {
            $set.="`$field`='".mysql_real_escape_string($source[$field])."', ";
        }
    }
    return substr($set, 0, -2);
}

// INSERT INTO DATABASE
            mysql_select_db("new_contact",$dbc) or die("Could not select new_contact");
            
$fields =   explode(" ", "RequestType ConsumerBusiness GlobalLocation FirstName LastName Email Title Company Address City State Zip Phone F ProductDesc Comment");
            $query = "INSERT INTO new_contact SET ".dbSet($fields, $_POST);
            mysql_query($query);

// SETUP EMAIL
	$Bodycopy = "This information was submitted via the ------.com website and sent to you because of the location 
        identified by the user. <br>If this has reached you in error, please forward this email to info@------.com";
	$Bodycopy. "<br>----------------------------------------------------------------------------------------------<br><br>";

        if ($RequestType != "")      $Bodycopy. "What kind of information do you need? : " .$RequestType. "<br>";	
	if ($ConsumerBusiness != "") $Bodycopy. "What type of customer or vendor are you? : " .$ConsumerBusiness. "<br>";
	if ($GlobalLocation != "")   $Bodycopy. "Global Location : " .$GlobalLocation. "<br>";
	if ($Company != "")          $Bodycopy. "Company : " .$Company. "<br>";
	if ($FirstName != "")        $Bodycopy. "First Name : " .$FirstName. "<br>";
	if ($LastName != "")         $Bodycopy. "Last Name : " .$LastName. "<br>";
	if ($Title != "")            $Bodycopy. "Title : " .$Title. "<br>";
	if ($Email != "")            $Bodycopy. "Email : " .$Email. "<br>";
	if ($Address != "")          $Bodycopy. "Address : " .$Address. "<br>";
	if ($City != "")             $Bodycopy. "City : " .$City. "<br>";	
	if ($State != "")            $Bodycopy. "State : " .$State. "<br>";
	if ($Zip != "")              $Bodycopy. "Zip/Postal Code : " .$Zip. "<br>";
	if ($Phone != "")            $Bodycopy. "Phone : " .$Phone. "<br>";
	if ($F != "")              $Bodycopy. "F : " .$F. "<br>";
	if ($ProductDesc != "")      $Bodycopy. "UPC or product description : " .$ProductDesc. "<br>";

	$Bodycopy. "<br>----------------------------------------------------------------------------------------------<br><br>";
        
	if ($Comment != "")          $Bodycopy. "Comments : <br>" .$Comment. "<br>";

        $Bodycopy. "<br><br>";
        $Bodycopy. $IP = $_SERVER["remote_addr"];
        
// PROCESS EMAIL

// mail server info...

        $from = $SendTo;
        $to = "Do Not Reply <donotreply@------>";
        $subject = "Website Contact : " . $GlobalLocation;
        $body = $Bodycopy;
        $host = "mail.------";
        $port = "25";
        $username = "donotreply@-------";
        $password = "-------";
        
        $headers = array ('From' => $from,
        'To' => $to,
        'Subject' => $subject);
        $smtp = Mail::factory('smtp',
        array ('host' => $host,
         'auth' => true,
         'port' => $port,
         'username' => $username,
         'password' => $password));
        
        $mail = $smtp->send($to, $headers, $body);
        
        if (PEAR::isError($mail)) {
        echo("<p>" . $mail->getMessage() . "</p>");
        } else {
        echo("<p>Message successfully sent!</p>");
        }

// MAKE SURE DB CONN IS CLOSED
        mysql_close($dbc);

// REDIRECT TO THANK YOU PAGE
        header ('Location: /index.php?option');
        exit();

}

?>

Link to comment
Share on other sites

First of all, when you post code please use code tags. And for the love of god, format the code so it is actually legible.

 

And secondly, whether or not it works is up to you to find out. We don't know or have access to your server environment; how are we going to know if it works or not?

Link to comment
Share on other sites

Actually, the forum's


code tag is undesirable as it adds a new-line character to the html source after every \t, \r and/or \n it finds, when the source code uses a different line ending than the one that the programmers were using when they wrote and tested the code for the


code tag. When you copy paste the code to help with it, you get hundreds of extra new-lines in it and it is a mess. The


tag should be used.

Link to comment
Share on other sites

Actually, the forum's


code tag is undesirable as it adds a new-line character to the html source after every \t, \r and/or \n it finds, when the source code uses a different line ending than the one that the programmers were using when they wrote and tested the code for the


code tag. When you copy paste the code to help with it, you get hundreds of extra new-lines in it and it is a mess. The


tag should be used.

 

Yeah, that aggravates me to no end.

Link to comment
Share on other sites

This thread is more than a year old.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.