Writing SMTP-Based SOAP Messages in PHP
By Shane Caraveo, October 01, 2002
With the buzz around web services, most SOAP usage has focused around the HTTP protocol, but other protocols can be used as well. SMTP has advantages not found with HTTP, including SMTP's ability to store and forward messages, implement one-to-many broadcast messaging, and use attachments to embed extra data into a SOAP message.
October 2002/Writing SMTP-Based SOAP Messages in PHP
Listing 4: Generating the image archive message
<?php
require_once("SOAP/Client.php");
$soapclient = new SOAP_Client("mailto:[email protected]");
$options = array(
'namespace'=>'http://server.com/imagearchive',
'from'=>'[email protected]',
'subject' => 'Image to archive',
'host' => 'smtp.domain.com',
'Attachments'=>-Mime-);
$filename = 'c:\\test\\someimage.jpg';
$image = new SOAP_Attachment('inputImage','imag/jpg',$filename);
$name = new SOAP_Value('imageName', 'string', 'sillyimage.jpg');
$messageid = $soapclient->call('archiveImage',array($name, $image), $options);
if (PEAR::isError($messageid)) {
echo 'we failed to deliver the image: '.$messageid->getMessage();
exit();
}
/* We successfully sent the image, we should store the message id
into some system so we can match up the URL we will get back later.
This is an unimplemented function, but you get the picture! ;) */
saveMessageIDToSomeDatabase($messageid);
?>