note 98173 added to function.openssl-pkcs7-encrypt

[email protected]
Newsgroups php.notes
Message-ID <[email protected]>
<?php
	SendEncryptedMail();
?>

<?php
function SendEncryptedMail()
{
	$ret = 0;
	$cert = "yourpubliccert.crt";
	$infile = "filetoencrypt.txt";
	
	$message = "";  // No message needed. It will be appended to the end of the headers.
	$to = "[email protected]";
	$subject = "Encrypted Message";

	$domain = "mailhost.com";
	$maildate = MailDate();
	$messageid = MessageID($domain,$maildate);
	
	$headers = 'To: <[email protected]>' . "\r\n";
	$headers .= 'From: <[email protected]>' . "\r\n";
	$headers .= $maildate;
	$headers .= $messageid;	
	
	
	$contenttype = "Content-Type: text/plain\r\n\r\n";  //The Content-Type: will be encrypted.

	$pkcs7 = PKCS7_encrypt($cert,$infile,$contenttype);
	$headers .= $pkcs7;  // Append the encrypted data to the end of the headers.

	$ret = mail($to, $subject, $message , $headers);
	if($ret)
		echo 'Mail sent.';
	else
		echo 'Mail send failed.';
	
	
}
?>

<?php

function PKCS7_encrypt($Cert,$Infile,$ContentType){
	
	$clearfile = tempnam("temp","email") . ".txt";
	$outfile = $clearfile . ".enc";
	$clearfile .= ".txt";
	$headers = array();  // No headers needed.
	
	
	$pubkey = file_get_contents($Cert);
	
	$txt = file_get_contents($Infile);

	$data = "";
	$message =  $ContentType . $txt;  // Create the message.  The ContentType: header must be the first line of the encrypted data.
	
	$len = strlen($message);
	$fh = fopen($clearfile,"w");
	fwrite($fh,$message,$len);
	fclose($fh);
																		
	$ret = openssl_pkcs7_encrypt($clearfile, $outfile, $pubkey, $headers);  	
	if($ret){																																		
		$data = file_get_contents($outfile);		
	}else{
		while ($msg = openssl_error_string())
		    echo $msg . "<br />\n";
	}	

	return $data;
}

?>

<?php
function MailDate()
{
	// Set your timezone 
	date_default_timezone_set('America/Los_Angeles');
	$today = 'Date: ' . date("D, j M Y G:i:s O") . "\r\n";
	return $today;
}
?> 

<?php
function MessageID($domain, $maildate)
{
	$id = md5($maildate);
	$messageid = 'Message-ID: ' . '<' . $id . '@' . $domain . '>' . "\r\n";
	return $messageid;
}
?>
----
Server IP: 69.147.83.197
Probable Submitter: 75.212.46.118
----
Manual Page -- http://www.php.net/manual/en/function.openssl-pkcs7-encrypt.php
Edit        -- https://master.php.net/note/edit/98173
Del: integrated  -- https://master.php.net/note/delete/98173/integrated
Del: useless     -- https://master.php.net/note/delete/98173/useless
Del: bad code    -- https://master.php.net/note/delete/98173/bad+code
Del: spam        -- https://master.php.net/note/delete/98173/spam
Del: non-english -- https://master.php.net/note/delete/98173/non-english
Del: in docs     -- https://master.php.net/note/delete/98173/in+docs
Del: other reasons-- https://master.php.net/note/delete/98173
Reject      -- https://master.php.net/note/reject/98173
Search      -- https://master.php.net/manage/user-notes.php
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.