Skip to content

Instantly share code, notes, and snippets.

@charlycoste
Last active December 22, 2015 02:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charlycoste/6404437 to your computer and use it in GitHub Desktop.
Save charlycoste/6404437 to your computer and use it in GitHub Desktop.
<?php
/**
* @author Charles-Edouard Coste
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
*/
include_once 'ezc/Base/ezc_bootstrap.php';
$soap_request = <<<EOD
<?xml version="1.0"?>
<soap:Envelope
xmlns:soap="http://www.w3.org/2001/12/soap-envelope"
soap:encodingStyle="http://www.w3.org/2001/12/soap-encoding">
<soap:Body xmlns:m="http://www.example.org/stock">
<m:GetStockPrice>
<m:StockName>IBM</m:StockName>
</m:GetStockPrice>
</soap:Body>
</soap:Envelope>
EOD;
$mail = new ezcMail();
$mail->from = new ezcMailAddress( 'cc@synap.fr', 'Me' );
$mail->addTo( new ezcMailAddress( 'robot@synap.fr', 'Hal' ) );
$mail->subject = "Give me the stock price of IBM";
// We create a plain text mail part for humans
$textPart = new ezcMailText( "Hello\n=======\n\nThis mail is a SOAP request. For robot eyes only." );
// We add a text/xml mail part for robots
$xmlPart = new ezcMailText($soap_request);
$xmlPart->subType = 'xml';
// Merging the two parts
$mail->body = new ezcMailMultipartAlternative( $textPart, $xmlPart );
$transport = new ezcMailSmtpTransport('smtp.xxx.xx');
$transport->send( $mail );
<?php
/**
* @author Charles-Edouard Coste
* @license http://www.gnu.org/licenses/gpl.html GNU General Public License
*/
require 'ezc/Base/ezc_bootstrap.php';
$server = new SoapServer('services.wsdl');
$options = new ezcMailImapTransportOptions();
$options->ssl = true;
$imap = new ezcMailImapTransport( "imap.xxx.xxx");
$imap->authenticate( "username", "password");
$imap->selectMailbox( 'Inbox' );
$set = $imap->fetchAll();
$parser = new ezcMailParser();
$mail = $parser->parseMail($set);
for ( $i = 0; $i < count( $mail ); $i++ )
{
$parts = $mail[$i]->fetchParts();
foreach ( $parts as $part )
{
if ( ( $part instanceof ezcMailText ) && $part->subType == 'xml' ) )
{
ob_start();
$server->handle($part->text);
$response = ob_get_flush();
// send $response in a mail, like in client.php
// ...
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment