Send Message to Yahoo! Messenger from PHP
Here is code example to send Yahoo! Messenger message using PHP. Make sure that your hosting system already installed with PHP curl library. This code last update on July 20, 2010 since Yahoo! change their mechanism again.
Now we already push this code the GitHub for public consume. You can improve or clone it if you want. Please go to http://github.com/sonyarianto/SendYMPHP.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | <?php // script name: send_message_to_yahoo_messenger.php // web scraper: Sony AK Knowledge Center - www.sony-ak.com // last update: July 20, 2010 // get home page of yahoo mobile $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, "http://us.m.yahoo.com/w/bp-messenger"); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_ENCODING, ""); curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14,52; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729)"); curl_setopt($curl, CURLOPT_COOKIEJAR, getcwd() . '/cookies_yahoo_messenger.cookie'); $curlData = curl_exec($curl); curl_close($curl); // debug: show the returned html // echo $curlData; exit; // get post url for login to yahoo $xml = $curlData; $xmlDoc = new DOMDocument(); @$xmlDoc->loadHTML($xml); $urlPostLoginToYahoo = $xmlDoc->getElementsByTagName("form")->item(0)->getAttribute("action"); foreach ($xmlDoc->getElementsByTagName("input") as $input) { if ($input->getAttribute("name") == "_done") { $_done = $input->getAttribute("value"); } if ($input->getAttribute("name") == "_ts") { $_ts = $input->getAttribute("value"); } if ($input->getAttribute("name") == "_crumb") { $_crumb = $input->getAttribute("value"); } } // do login to yahoo messenger (mobile version) $yahoo_id = "your_yahoo_id"; $yahoo_id_password = "your_yahoo_id_password"; $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $urlPostLoginToYahoo); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, "_authurl=auth&_done=" . $_done . "&_sig=&_src=&_ts=" . $_ts . "&_crumb=" . $_crumb . "&_pc=&_send_userhash=0&_partner_ts=&id=" . $yahoo_id . "&password=" . $yahoo_id_password . "&__submit=Sign+in"); curl_setopt($curl, CURLOPT_ENCODING, ""); curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14,52; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729)"); curl_setopt($curl, CURLOPT_COOKIEFILE, getcwd() . '/cookies_yahoo_messenger.cookie'); curl_setopt($curl, CURLOPT_COOKIEJAR, getcwd() . '/cookies_yahoo_messenger.cookie'); $curlData = curl_exec($curl); curl_close($curl); // get home page url for sending message $urlSendMessage = $curlData; $urlSendMessage = substr($urlSendMessage, strpos($urlSendMessage, "<a href=\"/w/bp-messenger/sendmessage") + 9); $urlSendMessage = substr($urlSendMessage, 0, strpos($urlSendMessage, "\"")); $urlSendMessage = str_replace("&", "&", $urlSendMessage); $urlSendMessage = "http://us.m.yahoo.com" . $urlSendMessage; // get home page of mobile messenger to send message $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $urlSendMessage); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_ENCODING, ""); curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14,52; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729)"); curl_setopt($curl, CURLOPT_COOKIEFILE, getcwd() . '/cookies_yahoo_messenger.cookie'); curl_setopt($curl, CURLOPT_COOKIEJAR, getcwd() . '/cookies_yahoo_messenger.cookie'); $curlData = curl_exec($curl); curl_close($curl); // debug: show the returned html // echo $curlData; exit; $xml = $curlData; $xmlDoc = new DOMDocument(); @$xmlDoc->loadHTML($xml); $urlPostSendMessage = $xmlDoc->getElementsByTagName("form")->item(0)->getAttribute("action"); $urlPostSendMessage = "http://us.m.yahoo.com" . $urlPostSendMessage; // do send message to yahoo messenger $yahoo_username = "sonyarianto"; // this is Yahoo! ID target $yahoo_message = "This is my message to you!"; // this is Yahoo! messenger message to the target $curl = curl_init(); curl_setopt($curl, CURLOPT_URL, $urlPostSendMessage); curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl, CURLOPT_POST, 1); curl_setopt($curl, CURLOPT_POSTFIELDS, "id=" . $yahoo_username . "&message=" . $yahoo_message . "&__submit=Send"); curl_setopt($curl, CURLOPT_ENCODING, ""); curl_setopt($curl, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.0; Trident/4.0; EmbeddedWB 14.52 from: http://www.bsalsa.com/ EmbeddedWB 14,52; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.5.30729; .NET CLR 3.0.30729)"); curl_setopt($curl, CURLOPT_COOKIEFILE, getcwd() . '/cookies_yahoo_messenger.cookie'); curl_setopt($curl, CURLOPT_COOKIEJAR, getcwd() . '/cookies_yahoo_messenger.cookie'); $curlData = curl_exec($curl); curl_close($curl); echo "your message already sent to Yahoo! ID: " . $yahoo_username; ?> |
If you have any problem, please send comment below or drop us e-mail to info@sony-ak.com. You can read other interesting articles on Sony AK Knowledge Center at www.sony-ak.com.





Hi,
I need complete web based Yahoo Im for my website Http://abaphr.com. Can you please help me out in this regard.
hi, how bout read message? can you mail me samples code? thanks
mas sony saya coba kalo baca pakai:
curl_setopt($curl, CURLOPT_GET, 1);
curl_setopt($curl, CURLOPT_GETFIELDS, “user=” . $yahoo_username . “&message=” . $yahoo_message . “&wmlfix=Read”);
tapi gak jalan ya? ada pencerahan? trims
@boentoro hi, I am still not experimenting for read message from Yahoo! Messenger, but the logic is simple, login to yahoo messenger mobile edition and check for incoming new message and then you can process for further purpose.
@boentoro code lengkapnya seperti apa?
Mas saya sudah coba script nya,tapi dari ym yang di kirim kok tidak bisa baca pesannya.kalo kita mau read pesannya bisa apa tidak ya?
mohon pencerahannya.
Thanks
@si_3188 hehehe khan emang itu script untuk ngirim pesan, bukan baca pesan
kalo mau read YM message ya kudu bikin script yg lain lagi fungsinya mas
code-nya udah gak jalan lagi ya mas?
@orakanggo masih jalan kok, barusan aku check lagi dan it’s fine
silakan dicoba lagi mas
mas.. sript dari mas sony… sudah saya coba dan muncul “your message already sent to Yahoo! ID: sonyarianto”
mas.. sript dari mas sony… sudah saya coba dan muncul “your message already sent to Yahoo! ID: sonyarianto” terus bagaimana ini….
@yono lha bagaimana apanya mas? silakan dicoba ajah send ke ID YM Anda sendiri
Bro Sony, saya sudah mencoba dan mengganti tujuan pesannya, saya upload di hosting hostgator dan berhasil muncul “your message already sent to Yahoo! ID: csstasiunpulsa”. Tetapi ym tujuan tidak pernah mendapatkan pesan yang saya kirim ini, apakah ada solusinya? Terima Kasih
@handoyo yup sepertinya si Yahoo! mengubah mekanisme login untuk Yahoo! Mobile nya, ok gak masalah, saya lg benerin dengan code yang lebih baru
@handoyo please try again, I already update with new web scraping code.
Terima kasih banyak Bro Sony, sudah jalan sekarang. Oia, banyak yang curi script bro sony buat dipasang di blog-nya sendiri lho, cman bedanya, hanya penulis aslinya saja yang dapat merubah dan memperbaikinya
@handoyo ya beginilah resikonya kalo open-content
berkat ada laporan dari Anda saya jadi tahu kalo ada masalah di script nya, dan Alhamdulillah ada waktu juga untuk memperbaikinya
Thanks mas.
Thanks bgt Bang Sony, coding yang sangat berguna dan mantab..
@widyo thanks juga mas
Mas Sony AK. Terima kasih.
Sekalian mohon ijin untuk modifikasi. Tanpa minghilangkan “Sony AK Knowledge Center – http://www.sony-ak.com“
@rindudendam ok mas
Hi Sony,
Thank you so much for your code, I was the first person to your comments section and still waiting for your help. mean while Got some idea about design part and i need to connect to Yahoo messenger from my site http://abaphr.com. Your code explains about connecting to Yahoo mobile, I want to connect from my website http://abaphr.com. Can you Please let me know how to connect from my website.
@ramakrishna thank you, if you need specific request you can ask me via my e-mail…
Thanks will reach you at your email………….
Halo Mas Sony,
Saat saya coba di local, script ini jalan.
tp saat saya coba di hosting, script ini ga jalan dan menghasilkan error ‘Empty reply from server’
kira2 apa ya penyebabnya?
Salam,
Kris
Mas, kalau script ini di jalankan secara terus menerus atau sending mesg ke lebih dari 1 atau 100 dalam selang waktu tertentu, Apakah ada potensi IP yang digunakan di Block sama yahoo?
Regards
@harry.
sepertinya ada kemungkinan diblock.
saya sudah mengalami, 4 jam pertama jalan sebagaimana mestinya, setelah itu ga jalan, padahal ga ada modif codenya.
kemungkinan diblock yahoo.
@kris ya maybe Yahoo! punya policy hit rate untuk itu, jadi mending gak terlalu rakus execute script nya huehehe
@mas sony ga rakus kok hehehe… saya cuman pake curl buat ngirim message ke ym saya…
Entah apakah Yahoo mengubah tipikal loginnya lagi ya? atau seperti kejadiannya bung Kris ada hit ratenya yang memblokir, saya kirim pesan memang muncul tulisan pesan terkirim tapi kok ngak ngepek ya ke YM saya..
Bagaimana jika saat melakukan pengiriman pesan kedua atau selanjutnya tidak perlu login lagi, tetapi langsung baca cookies terakhir yang kemudian langsung mengirim pesan. Mungkin yg diblok gara2 tiap kirim mondar mandir login lagi lagi lagi dan lagi.. itu maybe lho..
@widyo yoi coba di modif ajah code nya, atau code nya kita letakkan di github or bitbucket nih biar bisa diakses rame2
Script yang sangat super mas Sony..
Terima kasih banyak, saya sangat terbantu dengan script tsb.
Saya gunakan untuk notifikasi perubahan status developping program.
Sekali lagi terima kasih banyak..
Script yang bagus, belum sempat merasakan bisa kekirim apa ndak pakai script ini. kayak e dah ke blok duluan ama yahoo gara-gara pake script lain. dan sekarang account saya sering keluar masuk sendiri tanpa sebab. hiks hiks……. gimana ngatasinya yaaa ?