从此长大

杂 谈 赏 析
网 站 建 设
网 络 技 术
情 感 美 文
影 音 娱 乐
生 活 频 道
留 言 本
主 题 社 区

站 内 服 务
综合查询
心灵涂鸦板
祈愿漂流瓶
列车查询
网站信息
我的呵呵

您现在的位置:首页 / 学堂 /


WAP(wml)开发问答


2005-9-16 19:32:00 编辑:阿志 来源:来源网络


47. 如何使用WAP设备发送E-Mail?
在HTML中有一个默认的E-Mail机制:“ mailt” 。但在WML中不好使,因此E-Mails必须通过WML表单来解决。例如:

<wml>
     <card id="edit" title="Email Editor">
      <p>From: <input type="text" name="from" format="*M"/></p>
      <p>T <input type="text" name="to" format="*M"/></p>
      <p>Subject: <input type="text" name="subject" format="*M"/></p>
      <p>Message body: <input type="text" name="body" format="*M"/></p>
      <p>
        <anchor>Send this mail
          <go method="post" href="http://some.host/mailhandler"?action=send/">
            <postfield name="from" value="$(from)"/>
            <postfield name="to" value="$(to)"/>
            <postfield name="subject" value="$(subject)"/>
            <postfield name="body" value="$(body)"/>
          </go>
       </anchor>
      </p>
   </card>
</wml>

在代码中的http://some.host/mailhandler是一个CGI程序,它是服务端的脚本程序,将提交的表单转换成E-Mail格式并发送出去。
如果想使用一个类似于发信的过程,就需要编辑变量名。另外发送的数据是有限的,长信息可能需要打断。
为了演示它是如何工作的,下面的 PHP 脚本可以用来处理Mail。它将格式化WML页面,告诉用户是否发出信件。在真实的应用中,应该加入检测,例如:E-Mail的合法格式。
<?
// Tell the client that this is a WML deck
    header("Content-type: text/vnd.wap.wml");
    echo("<?xml version=\"1.0\"?>\n");
    echo("<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"
\"http://www.wapforum.org/DTD/wml_1.1.xml\">\n");
// The name of your mail server
    $mailer = "wap.colorline.no";
// Format the from field
    $from = $from." (WAP user at ".$mailer.")";
// Add the from field and some character handling to the extra headers
  $extraheaders = $from."\nContent-Type: text/plain;
charset=iso-8859-1\nContent-Transfer-Encoding: 8bit";
// Start sending out the WML deck
    echo("<wml>\n");
    if(mail($to,$subject,$body,$extraheaders))
{// Use PHP's internal mail functionality
// Mail was successfully sent
      echo("<card id=\"sent\" title=\"Mail sent\">\n");
      echo("<p>Mail was sent successfully</p>\n");
      echo("</card>\n");
    }
    else {
// The mail could not be sent
      echo("<card id=\"notsent\" title=\"Mail failed\">\n"); 
      echo("<p>Unable to send mail</p>\n");
      echo("</card>\n");
    }
    echo("</wml>\n");
?>


因为安全性的原因,以上的代码没有演示程序。

上一页 [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] 下一页




参与评论(条评论)
您的姓名:  您的Email:
评论内容:
250字内
发表评论:   发表评论须知 →
  • 尊重网上道德,遵守中华人民共和国有关法律法规;
  • 承担一切因您的行为导致的民事或刑事法律责任;
  • 本站管理人员有权保留或删除留言中的任意内容;
  • 本站有权在网站内转载或引用您的评论;