homepage Welcome to WebmasterWorld Guest from 54.226.191.80
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
sending MMS with sound file via PHP
How can I send a MMS through a MMS gateway, with a ring tone attached?
tnobs




msg:3568505
 1:45 pm on Feb 7, 2008 (gmt 0)

Hi

I have a website, and a MMS gateway, because I wanna send a MMS with a mp3 (ring tone) file to the user with php script. With this function below, I can send a normal text MMS, it's working. But how can I attach the mp3 file to the MMS? How to put the mp3 into the postdata?


function post($host, $path, $data)
{
$http_response = '';
$content_length = strlen($data);
$fp = fsockopen($host, 80);
fputs($fp, "POST $path HTTP/1.1\r\n");
fputs($fp, "Host: $host\r\n");
fputs($fp, "Content-Type: application/x-www-form-urlencoded\r\n");
fputs($fp, "Content-Length: $content_length\r\n");
fputs($fp, "Connection: close\r\n\r\n");
fputs($fp, $data);
while (!feof($fp)) $http_response .= fgets($fp, 28);
fclose($fp);
return $http_response;
}

$postdata = '?sender=72105&receiver=123456&subject=testsubject&message=testmessage&user=username&passwd=password';

foreach($_POST as $key => $val) $postdata .= '&'.$key.'='.$val;

$http_response = post('www.example.com', '/subsystem/postscript.php', $postdata);

echo $http_response;

If someone has an idea, how to attach a file to the MMS, that would be great.

Thanks, tnobs

 

ahmedtheking




msg:3568931
 8:31 pm on Feb 7, 2008 (gmt 0)

Hmm, I don't think you'd be able to encode a file and send it as vars. Have you tried asking your MMS gateway? Maybe they have a protocol whereby you send a var, let's say "mmsfile", that contains a url leading to a file only they can access and they then attach that?

tnobs




msg:3569702
 3:31 pm on Feb 8, 2008 (gmt 0)

I tried to do it with curl instead, but still I had the problem, that I don't know how to attach a soundfile. Do you need the rawdata, can get a raw data of a file easily with
$soundFileRaw = file_get_contents("sound.mp3");

I tried to use also this class: [phpclasses.org...]
but still, problems with attaching the sound.

The actual php code for curl is:

$url = 'www.example.com/subsystem/sendMMS.cfm';

$postData = array();

//simulates <input type="file" name="audio">
$postData[ 'file_name' ] = "[at] beatbox.mp3";

$postData[ 'sender' ] = "72105";

$postData[ 'receiver' ] = "0762312985";

$postData[ 'subject' ] = "test";

$postData[ 'message' ] = "Hello dear..";

$postData[ 'user' ] = "user";

$postData[ 'passwd' ] = "password";



// sender=72105&receiver=0762321985&subject=test 16:55&message='.$message.'&user=user&passwd=password

// at last make the submitbutton
$postData[ 'submit' ] = "UPLOAD";

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
curl_setopt($ch, CURLOPT_POST, 1 );

//Curl alredy knows its enctype='multipart/data'
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData );

$response = curl_exec( $ch );

echo $response;

Any other ideas?

[edited by: dreamcatcher at 6:50 pm (utc) on Feb. 8, 2008]
[edit reason] Use example.com, thanks. [/edit]

ahmedtheking




msg:3569867
 6:32 pm on Feb 8, 2008 (gmt 0)

There's no point encoding the file in anyway unless you know what your MMS gateway will do with it.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved