Last active
December 22, 2015 02:38
-
-
Save charlycoste/6404437 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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