Last active
November 23, 2017 13:43
Star
You must be signed in to star a gist
API fax unitaire exemple push PHP
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 | |
// Récupération du document en base64 | |
$filename = 'test-fax.doc'; | |
$binary = fread(fopen($filename, 'r'), filesize($filename)); | |
$binary = base64_encode($binary); | |
// Création du XML à poster | |
$xml = '<request login="your-login" password="your-password"> | |
<push media="fax" type="on_demand" name="Test API Fax PHP"> | |
<message type="doc">'.$binary.'</message> | |
<recipients> | |
<add target="+33 170248254"/> | |
</recipients> | |
</push> | |
</request>'; | |
// Création d'un socket | |
$fp = fsockopen('api.express-mailing.com', 80); | |
if ($fp === false) die("Serveur d'API Express-Mailing non disponible"); | |
// Construction et envoi de la requête HTTP | |
$request = "POST http://api.express-mailing.com/transac/api.ashx HTTP/1.0\r\n"; | |
$request .= "Host: api.express-mailing.com\r\n"; | |
$request .= "Connection: Close\r\n"; | |
$request .= "Content-type: application/x-www-form-urlencoded\r\n"; | |
$request .= "Content-Length: ".strlen($xml)."\r\n"; | |
$request .= "\r\n"; | |
$request .= $xml; | |
fwrite($fp, $request); | |
$response = ''; | |
while (!feof($fp)) | |
{ | |
$response .= fgets($fp, 1024); | |
} | |
fclose($fp); | |
die($response); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment