/* CGI script to transfer data from form to email address. MUST BE CUSTOMIZED. */ /* Libraries for the C compiler */ #include #include /* Customization */ #define SUBJECT 'Emails subject' #define EMAIL your_email_address@yourisp.net /* Prototype of strcpy function */ char * strcpy(char*, const char*); /* Main function dealing with output */ int main(void) { /* Local variables to be used */ char surname[100]; char name[100]; char age[100]; char occupation[100]; char address[100]; char city[100]; char pcode[100]; char country[100]; char request[2000]; FILE *cfPtr; int i; /* Initialisation of all local strings */ for(i=0; i<100; i++) { surname[i]='\0'; name[i]='\0'; name[i]='\0'; age[i]='\0'; occupation[i]='\0'; address[i]='\0'; city[i]='\0'; pcode[i]='\0'; country[i]='\0'; request[i]='\0'; } for(i=100; i<2000; i++) { request[i]='\0'; } /* Assigning WWW values to locals. If Web decoder is: -uncgi then use getenv("WWW_xxxxxxxxx") -cgiparse then use getenv("FORM_xxxxxxxxx") THIS IS VERY IMPORTANT FOR THE SCRIPT TO WORK!!! */ /* strcpy(surname, getenv("WWW_person_surname")); strcpy(name, getenv("WWW_person_name")); strcpy(age, getenv("WWW_person_age")); strcpy(occupation, getenv("WWW_person_occupation")); strcpy(address, getenv("WWW_person_address")); strcpy(city, getenv("WWW_person_city")); strcpy(pcode, getenv("WWW_person_pcode")); strcpy(country, getenv("WWW_person_country")); strcpy(request, getenv("WWW_person_request")); */ /* HTML document to print message */ printf("Content-type: text/html\n\n"); printf("Your name" "

"); /* Processing to insert data from local variables to a text document, and saves it as defined in customisation */ if((cfPtr= fopen("form.txt", "w")) == NULL) { printf("SORRY: Document could not be submitted.Try again " "later...

\n"); return 0; } else { fprintf(cfPtr, "INTERNET FORM RECEIVED\n"); fprintf(cfPtr, "Please answer as soon as possible...\n"); fprintf(cfPtr, "Name: %s %s\n\n", surname, name); fprintf(cfPtr, "Address: %s\n\t%s\n\t%s\n\t%s\n\n", address, pcode, city, country); fprintf(cfPtr, "Age: %s\n\n", age); fprintf(cfPtr, "Occupation: %s\n\n", occupation); fprintf(cfPtr, "--------------- QUERY ---------------\n\n"); fprintf(cfPtr, "%s\n--END OF EMAIL--\n", request); fclose(cfPtr); } system("mail -s SUBJECT EMAIL \n"); return 0; } /* End of program */