home *** CD-ROM | disk | FTP | other *** search
/ The HTML Web Publisher's Construction Kit / HTMLWPCK.ISO / unix / cgi / c_src / mailer.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-07-27  |  2.2 KB  |  80 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "util.h"
  4. #define MAILER          "/usr/ucb/mail"
  5. #define USER            "you@youraddress.edu"
  6. #define SUBJECT         "Webpage_Reply"
  7. #define LF              10
  8. #define MAX_ENT         10000       /*  max number of variables
  9.                                        that can be sent from form*/
  10. #define FROM            0
  11. #define EMAIL           1
  12. #define USUBJECT        2
  13. #define BODY            3
  14. typedef struct {
  15.                char *name;
  16.                char *val;
  17.                } entry;
  18.  
  19. void main(int argc, char *argv[])
  20. {
  21.  
  22.        entry entries[MAX_ENT];
  23.        int cont_len,index,marker;
  24.        char address[256];
  25.        FILE *mdata, *log;
  26.  
  27.        index=marker=0;
  28.  
  29.        cont_len = atoi(getenv("CONTENT_LENGTH"));
  30.  
  31.    for(index=0;cont_len&& (!feof(stdin));index++)
  32.    {
  33.        marker=index;
  34.        entries[index].val = fmakeword(stdin,'&',&cont_len);
  35.  
  36.                plustospace(entries[index].val);
  37.  
  38.        unescape_url(entries[index].val);
  39.        entries[index].name = makeword(entries[index].val,'=');
  40.    }
  41.  
  42.        /* put together e-mail address */
  43.  
  44.        sprintf(address, "%s -s %s %s",
  45.                MAILER, SUBJECT, USER);
  46.  
  47.        /* open pipe to mailer */
  48.  
  49.        if (!(mdata=popen(address,"w"))){
  50.                printf("<h1>Unable to open mail pipe</h1>%c",LF);
  51.                exit(-1); }
  52.  
  53.        /* send data to mailer */
  54.  
  55.        fprintf(mdata,"Subject: %s%c%c",entries[USUBJECT].val,LF,LF);
  56.        fprintf(mdata,"%s %c",entries[BODY].val,LF);
  57.        fprintf(mdata,"%c%cMessage Sender: 
  58. %s",LF,LF,entries[FROM].val);
  59.        fprintf(mdata,"%c%cEmail: %s",LF,LF,entries[EMAIL].val);
  60.  
  61.        /* put together HTML confirmation for mosaic user */
  62.  
  63.        printf("Content-type: text/html%c%c",LF,LF);
  64.  
  65.        printf("<h1>Mail sent!</h1> %c",LF);
  66.        printf("<h2>If you included an e-mail address you should 
  67. receive
  68.                a reply shortly.</h2>");
  69.        printf("content follows:<p><hr>%c",LF);
  70.  
  71.    for(index=0; index <= marker; index++)
  72.        printf("%s:  %s<p>",entries[index].name,
  73.               entries[index].val);
  74.    printf("<p><a href=\"http://found.cs.nyu.edu/\">RETURN</a><p>");
  75.  
  76.        pclose(mdata);
  77.        exit(0);
  78. }
  79.  
  80.