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

早就听闻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);
}

真强大,博客留言短信通知》有21个想法

  1. Xiaoxia

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

    回复
  2. to_be

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

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

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

    回复
  3. sheepherder

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

    回复
  4. Xiaoxia

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

    回复
  5. Pingback引用通告: 匿名

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注

此站点使用Akismet来减少垃圾评论。了解我们如何处理您的评论数据