Xiaoxia[PG]

真强大,博客留言短信通知

Internet20 条评论

早就听闻139移动邮箱有免费通过手机短信接收邮件的功能,于是在之前也开通了,但一直没有使用。

刚听一位网友说通过这个做了一个短信留言功能,哈哈,我也玩一玩!

现在在我的博客评论文章或者给我留言都会给手机发送一条短信,原理很简单,就是博客程序通过smtp发送一个邮件给移动的139邮箱,然后如果开启了短信通知功能的话,服务器会给你的手机发送一条长度在350字(还是字节呢?)内的短信。

贴php的邮件代码,留着以后使用。

function smtp_mail( $server, $mail_user, $mail_pass, $subject, $from, $to, $content )
{
   $mlog = "connecting to smtp server " . $server . "\n";
   $fd = fsockopen( $server, 25 );
   //Do you think it necessary to convert it?
   $subject = iconv('utf-8', 'gbk', $subject );
   if( !$fd ){
       $mlog .= "failed.";
   }else{
       socket_set_blocking( $fd, true );
       $reply = fgets( $fd, 1024 );
       if( !preg_match("/^220/", $reply ) ){
           $mlog .= "failed to get reply message.\n" . $reply . "\n";
       }else{
           $mlog .= "smtp started\n";
           fputs( $fd, "HELO ". "Xiaoxia" . "\r\n" );
           $reply = fgets( $fd, 1024 );
           if( !preg_match("/^250/", $reply ) )
               $mlog .= "HELO failed.\n" . $reply . "\n";
           fputs( $fd, "AUTH LOGIN" . "\r\n" );
           $reply = fgets( $fd, 1024 );
           if( !preg_match("/^334/", $reply ) )
               $mlog .= "AUTH LOGIN failed.\n" . $reply . "\n";
           fputs( $fd, base64_encode($mail_user) . "\r\n" );
           $reply = fgets( $fd, 1024 );
           if( !preg_match("/^334/", $reply ) )
               $mlog .= "AUTH USER failed.\n" . $reply . "\n";
           fputs( $fd, base64_encode($mail_pass) . "\r\n" );
           $reply = fgets( $fd, 1024 );
           if( !preg_match("/^235/", $reply ) )
               $mlog .= "AUTH PASSWORD failed.\n" . $reply . "\n";
           fputs( $fd, "MAIL FROM: $from" . "\r\n" );
           $reply = fgets( $fd, 1024 );
           if( !preg_match("/^250/", $reply ) )
               $mlog .= "MAIL FROM failed.\n" . $reply . "\n";
           fputs( $fd, "RCPT TO: $to" . "\r\n" );
           $reply = fgets( $fd, 1024 );
           if( !preg_match("/^250/", $reply ) )
               $mlog .= "RCPT TO failed.\n" . $reply . "\n";
           fputs( $fd, "DATA" . "\r\n" );
           $reply = fgets( $fd, 1024 );
           if( !preg_match("/^354/", $reply ) )
               $mlog .= "DATA failed.\n" . $reply . "\n";
           fputs( $fd, "From: $from" . "\r\n" );
           fputs( $fd, "Subject: $subject" . "\r\n" );
           fputs( $fd, "Content-Type: text/plain; charset=\"utf-8\"\r\n" );
           fputs( $fd, "To: $to" . "\r\n" );
           fputs( $fd, "\r\n" );
           fputs( $fd, $content . "\r\n" );
           fputs( $fd, "\r\n" . "." . "\r\n" );
           $reply = fgets( $fd, 1024 );
           if( !preg_match("/^250/", $reply ) )
               $mlog .= "DATA failed.\n" . $reply . "\n";
           fputs( $fd, "QUIT" . "\r\n" );
           $reply = fgets( $fd, 1024 );
           if( !preg_match("/^221/", $reply ) )
               $mlog .= "QUIT failed.\n" . $reply . "\n";
           $mlog .= "smtp finished.\n";
       }
       fclose( $fd );
   }
   global $pathinfo;
   $mlog .= "\n";
   $fp = fopen($pathinfo["dirname"]."/maillog.txt", "a");
   fwrite($fp,$mlog);
   fclose($fp);
}

20 条评论

  1. 喂喂,小虾收到吗?!
    test test!

  2. 收到! 哈哈~

  3. 亲爱的 我来了

  4. suanzi这条没通知,发现被认为是垃圾邮件了。。。
    不知道是不是我没有把发送者的邮箱地址添加到通讯录,哈哈!

  5. 原来可以用白名单的。。。 问题解决了!

  6. 揉脸,我来刷评论了

  7. 揉脸,我来刷评论了+1

  8. 对,是揉脸!

  9. 好吧,/傲慢

  10. 不要刷评论

  11. 前来膜拜小虾大牛

  12. 反向膜拜!

  13. 用飞信也行。。哈

  14. “350字(还是字节呢?)”

    UTF-8编码:350/3=116字,呵呵。

    有个人在我的博客留言,他的手机也是有新邮件就会通知的,结果,我回应他的评论,他的手机就响了,他回应,我再回应,结果他就郁闷了:为啥手机会老是响的呢。
    为了不让他郁闷,我就不马上回应他的评论了。

  15. 呵呵,这个可以做动态密码了,我Bolg以前用google日历的API,他那个提醒是延迟一分钟的,有这个就好了,哈哈

  16. 我之前也做了个这功能,我还用这个功能每天自动采集天气预报发到我邮箱再到手机上呢

  17. 免费的天气预报短信,的确不错!!!

  18. 虾老大,你的网站域名、空间到哪申请的?费用一年多少?

  19. @osbin:暂用rashost的linux vps,68¥每月。域名在国内申请,50¥每年,也便于管理。现在合租一个vps放多几个网站,也挺不错!

  20. 哦 晓得了 谢谢

发表评论

评论会经过自动审核,链接请勿超过 3 个。