sendMsg is a class which allows you to send a message to a contact from a specified account. It logs in, changes status to online, creates a new IM session with the target user, sends the message and ends both connections.
The Messenger server imposes a limit on how many IM sessions can be created per minute, so the script is not suited for sending messages to large numbers of contacts within the same login session (see below).
The user sending the message must be on the allow list of the receiving user; or, the target user must have “All others” on their allow list (as in the Windows Live Messenger options dialog). To get the login ticket for authentication it uses the MSNPAuth class, which is included in the ZIP file.
Because of the way the protocol works, the sending user doesn’t appear to come online because it does not synchronize lists.
This class has not been extensively tested, if you find a bug or error, please post a comment here.
Using sendMsg
Standard sending precedure - logging in, creating an IM session and sending a message:
$sendMsg = new sendMsg();
$sendMsg->login('sender@hotmail.com', 'password');
$sendMsg->createSession('recipient@hotmail.com');
$sendMsg->sendMessage('message', 'Times New Roman', 'FF0000');
The last two arguments for sendMessage() which specify font options are optional. The receiving client’s default font will be displayed if they are not specified.
createSession() should only be called a maximum of 8 times in any 60 second period, due to limits imposed by the Messenger service. The script will throw an error if you try calling createSession a 9th time.
Once createSession() has been called, sendMessage() can be used to send any number of messages to that user, for example:
$sendMsg = new sendMsg();
$sendMsg->login('sender@hotmail.com', 'password');
$sendMsg->createSession('recipient@hotmail.com');
$sendMsg->sendMessage('this is the first message');
$sendMsg->sendMessage('this is the second message');
$sendMsg->sendMessage('this is the third message');
createSession() can be called for each user that requires a message to be sent to. To send two messages to two different users:
$sendMsg = new sendMsg();
$sendMsg->login('sender@hotmail.com', 'password');
$sendMsg->createSession('firstperson@hotmail.com');
$sendMsg->sendMessage('hello first person');
$sendMsg->createSession('secondperson@hotmail.com');
$sendMsg->sendMessage('hello second person);
There is also a function which simplifies the procedure of sending a message to a single user:
$sendMsg = new sendMsg();
$sendMsg->simpleSend('sender@hotmail.com', 'password', 'recipient@hotmail.com','message');
The result property can be used to see how it went, refer to the constant definitions at the top of sendMsg.php for textual meaning. For description of socket errors, you can check the property error.
You can give it a try at the sandbox. If you have troubles getting the script working with connections error, please refer to Troubleshooting phpListGrab (phpListGrab uses similar code).

I always get following error:
Invalid password and/or password.
However if I try online demo at sandbaox, it works perfectly.
Is there any update which was missed in sendMsg.zip file? I also tried update MSNAuth class also (version 1.1.2)
The download link for sendMsg.zip was missing. THe link is : http://downloads.fanatic.net.nz/dev/php/sendMsg.zip
Other downloads at:
http://downloads.fanatic.net.nz/dev/php/
Hope this helps some who got here through Google
Thanks Ramon. It used to show at the bottom with WordPress’s meta feature, but I’ve just put up a new theme and it doesn’t display the meta. Will have to modify accordingly.
The script linked to in comments makes a connection and then goes into a receive loop. Any info on how to actually initiate (send) a message, like your sandbox script does? Can we see some source code for the actual sandbox script?
My mistake; works fine - thanks!
I can not get this to work on my server - everytime the form is submitted, i just get a blank page and the following line in the error logs on the server:
[12-Jan-2007 11:35:18] PHP Warning: fsockopen(): unable to connect to messenger.hotmail.com:1863 in /home/instants/public_html/imtest/sendMsg.php on line 35
Any ideas? TIA.
That’s usually because the server is blocking the connection, see this post about troubleshooting phpListGrab (which uses the same code).
Works pretty well for us.
Thanks Daniel.
Vinu
this works perfectly, but one thing:
it fails to send any messages when the account recieves any offline messages.
it simply just hangs there and stops responding.
I’m using this with PHP 4.4.4-8 and it keeps giving me invalid password even though it isn’t invalid. Any ideas?
i get a PHP Notice: Undefined index: MSNPauth_Key in E:\msnpauth.php on line 39
help? i have faith in this script i think its an error on my part! how can I fix it?
[quote comment="23169"]i get a PHP Notice: Undefined index: MSNPauth_Key in E:\msnpauth.php on line 39
help? i have faith in this script i think its an error on my part! how can I fix it?[/quote]
I’m getting same error message with you.How i can fix it?Online example works perfectly but zipped file doesn’t work
Replace msnpauth.php with one of the two available here. The one in the zip on this page is old.
The site looks great ! Thanks for all your help ( past, present and future !)
is it possible to send mail to all your msn contacts using this, or it should be modified for that kind of use ?
I found the following error when executing the script.
I am quite new to php scripting and am a basic learner.
Please help me.
Fatal error: Call to undefined function curl_init() in C:\wamp\www\msnmessenger\msnpauth.php on line 26
How can I modify it to send multiple messages or a messages to multiple contacts. Thanks. Sorry but my english is not good.
Howdy. Something’s up right here. On my test system, upon sending a test message nothing happens. All I get is a white page, no code within it.
In the sandbox, it keeps trying to tell me the user is not signed in…when I am.
Edit: Looked into it a bit. Looks like you’ve tried calling function curl_init() but it’s not defined anywhere within the code, whether this be in the original msnpauth or the the cURL version and the fopensock version just causes my apache error.log to expand to hundreds of megs.
Edit2: Ignore the “user is not logged in” issue: it was just me not adding the test account to my friends list.
So now, the only issue is this curl_init() function
Edit3: Weird the curl libraries and their dependancies are all set up in PHP. PHP’s set up just fine…so why isn’t it recognising curl_init()?
Edit4: Right, fully sorted the PHP install, basically it meant me copying 2 or 3 dlls to every sys dir on my system…blegh.
New problem: Now it never recognises my username/password combo. The sandbox works fine, however.
Edit…lots:
[Tue Jul 03 12:07:56 2007] [error] [client 127.0.0.1] PHP Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://login.passport.com:443 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in C:\\Program Files\\Apache Software Foundation\\Apache2.2\\htdocs\\msnpauth.php on line 67, referer: http://127.0.0.1:8080/index.php
This appears in my error.log each time I’m using the fsockopen function. Thankfully, it only does this now, had to modify the code slightly so it wouldn’t inflate the log to 1/2 gig.
The cURL version (both) simply don’t authorize the username/pass combo. Would this be something to do with a prt forwarding issue?
When will the release of the sandbox version be?
The current released version does not work… keeps saying my password is incorrect but the sandbox one works
I have just got a new lap top i have been useing msn account and want to use same account can i? The account is in my partners name robinjardine@msn.com
i used msn on my house computer how do i get it on my lap top to send im etc:?
Unfortunately no message can be sent when recepient is offline :-/
I get the following:
Notice: Undefined index: SB in /var/www/msn/phplistgrab.zip_FILES/sendMsg/sendMsg.php on line 143
its giving error like unexpected varibale
will there be a msnp 15 version?
I try send message to 3 user, but if first user off-line other user will be off-line too. can you resolve it.
Nice ****ing class.
i don’t understand now this script work or not work
Hi, i tried to use the class but almost always i resive this error:
Warning: fputs(): supplied argument is not a valid stream resource in /home/xxxx/public_html/sendMsg.php on line 143
i’m can you help me?
Regards
Hi there,
I think I found a little problem…. If you wish to send consecutive messages to 2 or more users the loop will stop when you find the first offline user.
The reason is the code on line 48 on file sendMsg.php:
// Stop if login failed.
if ($this->result > 1)
{
return;
}
$this->result will be 217 if the previous user was offline, so it wont start a new session with next consecutive user and te problem will occur in every single step of the loop after the point where the first offline user was found.
The same problem will occurr with results that are numerically greater than 1.
Hope this helps,
Reinaldo
help
Fatal error: Maximum execution time of 60 seconds exceeded in C:\xampp\htdocs\new\sendMsg\sendMsg.php on line 120
$gettotal=intval(@$_POST['totalemail']);
$start=0;
$procesados=0;
$sendMsg = new sendMsg();
$sendMsg->login($_POST["sender"], $_POST["password"]);
while($start!=$gettotal)
{
$start++;
$email=stripslashes(@$_POST['email'.$start]);//one email at a time
$emailss=htmlspecialchars($email,ENT_QUOTES);
$asunto=”hola $emailss probandooo”;
if ($email!=”")
{
$procesados++;
//send
$sendMsg->createSession($emailss);
$sendMsg->sendMessage($asunto);
switch ($sendMsg->result)
{
case ERR_AUTHENTICATION_FAILED:
echo $email.” - Login Incorrecto.”;
break;
case ERR_SERVER_UNAVAILABLE:
case ERR_INTERNAL_SERVER_ERROR:
echo $email.” - Algo fue mal al intentar conectar al server.”;
break;
case USR_OFFLINE:
echo $email.” - El usuario no estaba conectado.”;
break;
case OK:
echo $email.” - Enviado.”;
break;
default:
echo $email.” - Error: “.$phpnickchange->result.”";
}
}
}
Solo manda al primer correo =(
Hello everyone! I want to send message to YM, how can i do it?
please help me!
for send a message ALL contact?? Without writing any Contacts
Hello. this script is very nice but I need to receive answers back. Does anybody have an idea how to receive? thanks
Hi!
can anyone contact me regarding this script? hurripane at gmail dot com
thanks!
it didn’t work for me, but check this out
http://thinker.rubay.de/archives/20-PHPurple-v0.2-alpha-released.html
this one works
Nice idea but I get this one
Warning: fputs(): supplied argument is not a valid stream resource in /home/prelovac/public_html/sendmsn/sendMsg.php on line 147
PHP Notice: Undefined index: SB in /var/www/html/sendMsg.php on line 143
PHP Warning: fputs(): supplied argument is not a valid stream resource in /var/www/html/sendMsg.php on line 143
Content-type: text/html
X-Powered-By: PHP/4.3.9
I found sendMsg is bug
Sender password is not long ,I try password is zxcvbnm,.741852963
command line is error 911
web message is error Invalid passport and/or password.
I change password is OK.
The script tells me that the recipient is offline (err 217) even if it is connected.
This issue does not occur with some recipients.