curl_setopt($ch, CURLOPT_REFERER,"URLHERE");
curl_setopt($ch, CURLOPT_URL,"URLHERE");
curl_setopt($ch, CURLOPT_POST, 0);
$page = curl_exec($ch);
$formtoken = explode('name="formtoken" type="hidden" value="',$page);
$formtoken = explode('"/> ',$formtoken[1]);
$formtoken = $formtoken[0];
$backto = explode('type="hidden" name="backto" value="',$page);
$backto = explode('" />',$backto[1]);
$backto = $backto[0];
curl_setopt($ch, CURLOPT_COOKIEFILE, "/tmp/cookiejar-$randnum");
curl_setopt($ch, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_URL,"URLHERE");
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_POST, 1);
$postfields = "formtoken=".$formtoken;
$postfields .= "&backto=".$backto;
$postfields .= "&message=".$msg;
$postfields .= "&submit=Post";
curl_setopt($ch, CURLOPT_POSTFIELDS,$postfields);
$page = curl_exec($ch);