I'm looking for a C/C++ script which send automatically a mail to a
person, who has just subscribed to a form, in order to tell him that
his subscription is successful.
For the moment, the CGI i found for that, are written with Perl.
Thanks.
Alexandra
Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
--
PLEASE NOTE: comp.infosystems.www.authoring.cgi is a
SELF-MODERATED newsgroup. aa.net and boutell.com are
NOT the originators of the articles and are NOT responsible
for their content. You can SELF-APPROVE your first posting
by writing the word 'passme' on a line by itself.
Please find below a C function that does what you want. A couple of
comments about this function:
1) TMP_DIR = "/tmp/"
2) If there is an object in the form that is called "hideEmailTo" then
the email message is sent to the address in the value of the object
(this is not recommended and it is a security hole... I think). Else,
the email message is sent to EMAIL_ADDRESS and (if not an empty string)
to EMAIL_ADDRESS2.
Good Luck and questions are welcome.
Sleiman
----------------------------
C function starts here:
----------------------------
int emailForm(){
FILE *Email;
char *cSenderEmail, *cSenderName, *cEmailTo;
char system_cmd[ 200 ], *subject;
char email_filename[ ] = TMP_DIR "emailXXXXXX";
int x, index;
mktemp( email_filename );
if( !(Email = fopen( email_filename, "w" ) ) ){
sprintf( error_message, "Error!<P>"
"An error occured on the System and your form could not be "
"handled properly. Please send an email to " EMAIL_ADDRESS
" and notify them of the error.<P>"
"Error Details: Could not open the temporary file (%s) to send "
"an email.<P>", email_filename );
return( 1 );
}
if( ( ( index = entry_index( "hideEmailSubject" ) ) >= 0 ) &&
( strlen( entries[ index ].val ) > 1 ) )
subject = entries[ index ].val;
else{
subject = ( char * ) malloc( 10 * sizeof( char ) );
strcpy( subject, "No Subject" );
}
if( ( ( index = entry_index( "Sender Name" ) ) >= 0 ) &&
( strlen( entries[ index ].val ) > 1 ) )
cSenderName = entries[ index ].val;
else{
cSenderName = ( char * ) malloc( 10 * sizeof( char ) );
strcpy( cSenderName, "No Name" );
}
if( ( ( index = entry_index( "Sender Email" ) ) >= 0 ) &&
( strlen( entries[ index ].val ) > 1 ) )
cSenderEmail = entries[ index ].val;
else{
cSenderEmail = ( char * ) malloc( 10 * sizeof( char ) );
strcpy( cSenderEmail, "No.Email" );
}
if( ( ( index = entry_index( "hideEmailTo" ) ) >= 0 ) &&
( strlen( entries[ index ].val ) > 1 ) )
fprintf( Email, "To: %s\n", entries[ index ].val );
else{
fprintf( Email, "To: " EMAIL_ADDRESS );
if( strlen( EMAIL_ADDRESS2 ) > 1 )
fprintf( Email, ", " EMAIL_ADDRESS2 );
fprintf( Email, "\n" );
}
fprintf( Email, "From: %s (%s)\n", cSenderEmail, cSenderName );
fprintf( Email, "Subject: %s\n\n", subject );
for( x = 0; x <= m; x++ )
if ( (strncmp( entries[x].name, "hide", 4 ) ) )
fprintf( Email, "%s = %s\n", entries[x].name, entries[x].val );
fclose( Email );
sprintf( system_cmd, MAIL " < %s", email_filename );
if( system( system_cmd ) ){
sprintf( error_message, "Error!<P>"
"Error occured while trying to process your form."
"Please send an email to " EMAIL_ADDRESS " and inform them "
"of the error.<P>"
"Error Details: Could not execute the system command %s<P>",
system_cmd );
unlink( email_filename );
return( 1 );
}
unlink( email_filename );
return( 0 );