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 6: Parsing an incoming e-mail and returning native data types
<?php
/* include the Email server class, which knows how to
parse a standard email as a SOAP message */
require_once 'SOAP/Server/Email.php';
/* include a class to access POP3 */
require_once 'Net/POP3.php';
/* create the SOAP server object */
$server = new SOAP_Server_Email;
/* connect to a POP3 server and read the messages */
$pop3 =& new Net_POP3();
if ($pop3->connect('localhost', 110)) {
if ($pop3->login('soap', 'password')) {
$listing = $pop3->getListing();
/* now loop through each message, and call the
SOAP server with that message */
foreach ($listing as $msg) {
$email = $pop3->getMsg($msg['msg_id']);
/* This is where we actually handle the SOAP
response. The SOAP::Server::Email class we
are using will send the SOAP response to
the sender via email. */
if ($email) {
$URL = $server->client($email);
$messageid = $server->headers['message-id'];
/* remove the message from the email storage*/
$pop3->deleteMsg($msg['msg_id']);
/* Now that we've got a URL, we need
to associate it with the message id we
previously stored. This function has been left
unimplemented. */
if (PEAR::isError($messageid)) {
// handle the error
print $messageid->getMessage();
} else {
AssociateURLwithMessageID($messageid,$URL);
}
}
}
}
$pop3->disconnect();
}
?>