Encrypt an S/MIME message - PHP

Im trying to create “application” for someone to fill out and send an encrypted mail from 1 address to another which are both controlled through godaddy im trying to get it to send from web -> dealer because my dealer email address has other email addresses that it forwards it to

Was woundering if someone can verify this script will work as intened

my html=

<form action="apply.php" ...

File name below is- apply.php

while (list($key, $val) = @each($_GET)) $GLOBALS[$key] = $val;
while (list($key, $val) = @each($_POST)) $GLOBALS[$key] = $val;
while (list($key, $val) = @each($_COOKIE)) $GLOBALS[$key] = $val;
while (list($key, $val) = @each($_FILES)) $GLOBALS[$key] = $val;
while (list($key, $val) = @each($_SESSION)) $GLOBALS[$key] = $val;

/* Gathering Data Variables */

$fnameField = $_POST['fname'];
$lnameField = $_POST['lname'];
$monthField = $_POST['month']
$dayField = $_POST['day'];
$yearField = $_POST['year']
$emailField = $_POST['email'];
$phonrField = $_POST['phone']
$residenceField = $_POST['residence'];
$addressField = $_POST['address'];
$cityField = $_POST['city'];
$stateField = $_POST['state'];
$zipField = $_POST['zip'];
$timemField = $_POST['timem'];
$timeyField = $_POST['timey'];
$idField = $_POST['id'];
$socialield = $_POST['social'];
$nosocialield = $_POST['nosocial'];
$employerField = $_POST['employer'];
$employnumField = $_POST['employnum'];
$extField = $_POST['ext'];
$titleField = $_POST['title'];
$employmField = $_POST['employm'];
$employyField = $_POST['employy'];
$incomeField = $_POST['income'];
$netField = $_POST['net'];
$hoursField = $_POST['hours'];
$addField = $_POST['add'];
$noaddField = $_POST['noadd'];
$howField = $_POST['how'];
$referField = $_POST['refer'];
$notesField = $_POST['notes'];


$data= <<<EOD





First Name: $fnameField

Last Name: $lnameField

Email: $emailField

Phone: 1+$phoneField

Social: $social $nosocField

Drivers License or ID number: $idField

DOB: $dobmField$dobdField$dobyField

Address: $addressField

City: $cityField

State: $stateField Zip: $zipField

Time at Address: $timemField Months $timeyField Years

Employer: $employerField Job Title: $titleField

Additional Income: $addField , $howField $noaddField

Employers Phone Number: $employnumField Ext: $extField

Time at Employer: $employmField Months $employyField Years

Gross Income: $incomeField , $netField , $hoursField

Referred by: $referField

Additional Info: $notesField

EOD;

// Setup mail headers.
$headers = array(“From” => "[email protected]", “To” => "[email protected]", “Subject” => “Application”, “X-Mailer” => “PHP/”.phpversion());

// Get the public key certificate.
$pubkey = file_get_contents(“hotshots.cer”);

// Header for encrypted part
$eol = “\r\n”;
$enc_header .= "From: ".$headers[‘From’].$eol;
$enc_header .= "To: ".$headers[‘To’].$eol;
$enc_header .= "Subject: ".$headers[‘Subject’].$eol;
$enc_header .= “Content-Type: text/plain; format=flowed; charset=“iso-8859-1”; reply-type=original”.$eol;
$enc_header .= “Content-Transfer-Encoding: 7bit”.$eol;
$enc_header .= “\n”;

// Prepend header for encrypted message
$body = file_get_contents(“body.txt”);
$msg = $enc_header.$data;
file_put_contents(“msg.txt”, $msg);

// Remove some double headers for mail()
$headers_msg = $headers;
unset($headers_msg[‘To’], $headers_msg[‘Subject’]);

// Encrypt message
openssl_pkcs7_encrypt(“msg.txt”, “enc.txt”,$pubkey,$headers_msg,0,1);

// Seperate headers and body for mail()
$data = file_get_contents(“enc.txt”);
$parts = explode("\n\n", $data, 2);

// send mail
mail($headers[‘To’], $headers[‘Subject’], $parts[1], $parts[0]);
?>

Next time, please place your code inside the PHP tags. Much easier for us…

Well, a quick review looks like it should work. Have you tested it so far? Did it throw out an error?
If you got errors post them and we will help. If not, let others know that it works. Good luck!

Sponsor our Newsletter | Privacy Policy | Terms of Service