PHP: Send PDF or other binary file with SendLetter()

<?php
 
/************* Settings  Begin ****************/
 
$filename = 'test.doc';  // file to be posted; contents need to conform to requirements (address in proper address area)
$username = '********';
$password = '********';
$description = 'My first letter through PostalMethods.com';
 
/************* Settings  End ******************/
 
 
 
 
// Open File
if( !($fp = fopen($filename, "r"))){
	// Error opening file
	// Handle error however appropriate for your script
	echo "Error opening file";
	exit;
}
 
// Read data from the file into $data
$data = "";
while (!feof($fp)) $data .= fread($fp,1024);
fclose($fp);
 
$soapclient = new SoapClient('http://api.postalmethods.com/PostalWS.asmx?WSDL');
$result = $soapclient->SendLetter(array('Username'    => $username,
                                     'Password'       => $password,
                                     'MyDescription'  => $description,  // free-form description for your records
                                     'FileExtension'  => end(explode(".", $filename)),  // make sure the extension reflects the file type
                                     'FileBinaryData' => $data)); // PHP5 does base64_encoding implicitly
 
 
//print_r($result);
 
$status_code = $result->SendLetterResult;  // $status_code is the (positive) transaction ID if successful, or a (negative) error number if unsuccessful
if ($status_code > 0){
	print "Message submitted successfully with transaction ID <b>$status_code</b>";
} else {
	print "Message submission failed on error <a href=\"http://www.postalmethods.com/resources/reference/status-codes\">$status_code</a>";
}
?>