<?php
/************* Settings Begin ****************/
$filename = 'test.doc'; // file to be posted; contents need to conform to requirements (address in proper address area)
$username = '********';
$password = '********';
$description = 'Sending a letter using PHP';
$mode = 'Default'; // Default, Production, or Development.
/************* 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('https://api.postalmethods.com/2009-02-26/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
'WorkMode' => $mode));
//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>";
}
?>