当前位置:中国站长下载文章中心网页制作HTML/CSS → 使用WAP设备发送E-Mail-wap发送邮件

使用WAP设备发送E-Mail-wap发送邮件

减小字体 增大字体 作者:佚名  来源:iwcpu.com  发布时间:2008-10-29 13:13:53

在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");

?>


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