;;; form-to-email.mhtml: -*- Meta-HTML -*- 

;;;  Copyright (c) 1996 Brian J. Fox
;;;  Author: Brian J. Fox (bfox@ai.mit.edu) Fri Jul 19 08:34:34 1996.
<defmacro form-to-email package=local>
  <alist-to-package <package-to-alist posted> "">
  <set-var %attributes>
  <FORM METHOD="POST" ACTION="<get-var mhtml::current-doc>">
    %body
    <p>
    <INPUT TYPE="SUBMIT" NAME="ACTION"
	   VALUE="<or <get-var action-name> "Submit Form">">
  </FORM>

  <when <string-eq <get-var-once posted::action>
		   <or <get-var action-name> "Submit Form">>>
    <with-open-stream s localhost:25 type=tcp mode=write-create>
      <stream-put s "HELO <get-var env::server_name>\r\n">
      <stream-put s "MAIL FROM: webmaster@<get-var env::server_name>\r\n">
      <stream-put s "RCPT TO: <get-var to>\r\n">
      <stream-put s "DATA\r\n">
      <stream-put s "From webmaster@<get-var env::server_name>\r\n">
      <stream-put s "To: <get-var to>\r\n">
      <if <get-var subject>
	  <stream-put s "Subject: <get-var subject>\r\n">>
      <stream-put s "\r\n">
      <stream-put s "<get-var body>\r\n">
      <stream-put s "\r\n.\r\n">
      <stream-put s "QUIT\r\n">
      <stream-get-contents s ignore>
    </with-open-stream>

    <if <get-var redirect-to>
	<redirect <get-var redirect-to>>>
  </when>
</defmacro>

<defmacro email-format>
  <set-var body=<prog %body>>
</defmacro>

		  
    
