Forum Moderators: coopster
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
$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]