#include <iostream.h>
#include <procbuf.h>
#include "pcgi.h"

void main()
    string Query;
    string rem_host;
    cin >> Query;
    Query = clean_query(Query);
    string rem_add(getenv("REMOTE_ADDR"));
    if(getenv("REMOTE_HOST") == '\0')
        rem_host.assign("unkown hostname");

    string wagent(getenv("HTTP_USER_AGENT"));
//'procbuf' class is a child of the 'streambuf' class, it is used to read/write
//from/to a pipe.
    procbuf mailer("/usr/sbin/sendmail -oi -t", ios::out);
//the 'form' method (defined in the 'streambuf' class is similar to the stdio.h
//'printf' fn.
    mailer.form("To: %s\n", cgi_query(Query, "sendto").c_str());
    mailer.form("From: %s <%s>\n", cgi_query(Query, "name").c_str(),  
                cgi_query(Query, "email").c_str());
    mailer.form("Subject: Feedback form\n\n");
    mailer.form(cgi_query(Query, "comments").c_str());
//add info about user sending feedback:
    mailer.form("\nName: %s", cgi_query(Query, "name").c_str());
    mailer.form("\nIP, hostname: %s (%s)", rem_add.c_str(), rem_host.c_str());
    mailer.form("\nEmail: %s", cgi_query(Query, "email").c_str());
    mailer.form("\nCountry: %s", cgi_query(Query, "country").c_str());
    mailer.form("\nURL: %s", cgi_query(Query, "url").c_str());
    mailer.form("\nHTTP client: %s", wagent.c_str());
    cout << "Content-Type: text/html\n\n";
    cout << "<html>\n<head>\n";
    cout << "<title>Feedback is sent...</title>\n</head>\n";
    cout << "<body bgcolor=\"#ffffff\">\n";
    cout << "<p>Thanks " << cgi_query(Query,"name")
         << ", for submitting your feedback...";
    cout << "\n\n<p>Click <a href=\"/\">here</a> to go back to our homepage.";
    cout << "\n</body>\n</html>";

1. Compile this code into your CGI binaries directory. Note that you need the pcgi.h header file in order to compile, click here to get it.
2. To use this CGI script from a certain HTML file, you should make a form in that file like this:

	<form action="/cgi-bin/feedback.cgi" method="POST">
	<input type="hidden" name="sendto" value="webmeister">
	<br>Name *: <input type="text" name="name" size="35">
	<br>Country: <input type="text" name="country">
	<br>Email *: <input type="text" name="email" size="30">
	<br>Nickname: <input type="text" name="nick">
	<br>Homepage: <input type="text" name="url" size="70" value="http://">
	<p>Comments *:
	<br><textarea name="comments" rows="5" cols="75"></textarea>
	<p><input type="submit" value="Submit">
You can change the HTML code for form as you like, provided the following:
. the form submitting method should be POST.
. the following input names should be provided: name, sendto, country, email, nick, url, comments.
if you want to remove some of those inputs then you'll have to edit the C++ feedback code as appropriate & remove any code lines using this input name & then you'll have to recompile that code.
. there must be a value for the hidden "sendto" input.

This code has been written using lpe & was converted to html using code2html.