Last active
March 15, 2023 01:20
-
-
Save charles85/5906198 to your computer and use it in GitHub Desktop.
How to Send multipart related MMS via MM7 Standard in PHP using CURL
This file contains hidden or 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 | |
$auth_basic = base64_encode(username:password); | |
$url = 'http://xxxx.xxx.xxx:xxxxx/mm7/xxxx.xxx'; | |
$boundary = uniqid(); // generate uniqe boundary | |
##Load animated graphics | |
$im = file_get_contents($image_path); | |
$img_data = base64_encode($im); | |
$mms_text_header = 'This is a MMS TEXT'; | |
$smil_cml = '<?xml version="1.0" encoding="UTF-8"?><smil><head><layout><root-layout width="100%" height="100%"/><region id="Text" top="50%" left="0" height="50%" width="100%" fit="hidden"/><region id="Image" top="0" left="0" height="50%" width="100%" fit="hidden"/></layout></head><body><par><img src="cid:a1.gif" region="Image"/><text src="cid:132c4ca56a209475" region="Text"/></par></body></smil>'; | |
##MMS XML | |
$send_XML = '<?xml version="1.0" ?> | |
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> | |
<SOAP-ENV:Header> | |
<TransactionID xmlns="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-3" SOAP-ENV:mustUnderstand="1">123123123123123</TransactionID> | |
</SOAP-ENV:Header> | |
<SOAP-ENV:Body> | |
<SubmitReq xmlns="http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-3"> | |
<MM7Version>5.3.0</MM7Version> | |
<SenderIdentification> | |
<VASPID>xxxxx</VASPID> | |
<VASID>xxxxxx</VASID> | |
<SenderAddress> | |
<ShortCode>xxxxx</ShortCode> | |
</SenderAddress> | |
</SenderIdentification> | |
<Recipients> | |
<To> | |
<Number>xxxxxxxx</Number> | |
</To> | |
</Recipients> | |
<ServiceCode>xxxxxx</ServiceCode> | |
<MessageClass>Personal</MessageClass> | |
<DeliveryReport>true</DeliveryReport> | |
<ChargedParty>Recipient</ChargedParty> | |
<ReadReply>false</ReadReply> | |
<Priority>Normal</Priority> | |
<Subject>MMSSUBJECT</Subject> | |
<DistributionIndicator>false</DistributionIndicator> | |
<Content allowAdaptations="false" href="cid:generic_content_id"/> | |
</SubmitReq> | |
</SOAP-ENV:Body> | |
</SOAP-ENV:Envelope> | |
'; | |
$headers = array("Content-Type: multipart/related; boundary=\"==$boundary==\"; type=text/xml; | |
start=\"<test-200104/mm7-submit>\"", | |
"authorization: Basic ".$auth_basic, | |
"soapaction: \"http://www.3gpp.org/ftp/Specs/archive/23_series/23.140/schema/REL-5-MM7-1-3/MM7/submitRequest\""); | |
$postData = "--==$boundary==\r\n" | |
."Content-Type: text/xml; charset=us-ascii\r\n" | |
."Content-Transfer-Encoding: 7bit\r\n" | |
."Content-ID: <test-200104/mm7-submit>\r\n\r\n" | |
.$send_XML."\r\n" // this is the xml data | |
."--==$boundary==\r\n" | |
."Content-Type: multipart/related; start=\"<mms.smil>\"; | |
boundary=\"==3222222.$boundary==\"; type=\"application/smil\"\r\n" | |
."Content-ID: <generic_content_id>\r\n\r\n" | |
."--==3222222.$boundary==\r\n" | |
."Content-Type: text/plain; charset=MS936\r\n" | |
."Content-Transfer-Encoding: 7bit\r\n" | |
."Content-ID: <132c4ca56a209475>\r\n\r\n" | |
.$mms_text_header."\r\n" | |
."--==3222222.$boundary==\r\n" | |
."Content-Type: image/gif; name=a1.gif\r\n" | |
."Content-Transfer-Encoding: base64\r\n" | |
."Content-Disposition: attachment; filename=a1.gif\r\n" | |
."Content-ID: <a1.gif>\r\n\r\n" | |
.$img_data."\r\n" // this is the content of the images | |
."--==3222222.$boundary==\r\n" | |
."Content-Type: application/smil\r\n" | |
."Content-Transfer-Encoding: 7bit\r\n" | |
."Content-ID: <mms.smil>\r\n\r\n" | |
.$smil_cml."\r\n" // this is the content of the text file | |
."--==3222222.$boundary==--\r\n\r\n" | |
."--==$boundary==--\r\n"; | |
$ch = curl_init($url); | |
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); | |
curl_setopt($ch, CURLOPT_VERBOSE, true); | |
curl_setopt($ch, CURLOPT_HEADER, 1); | |
curl_setopt($ch, CURLOPT_POST, 1); | |
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData); | |
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
$response = curl_exec($ch); | |
curl_close($ch); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment