I am currently writing CGI script which can accept user inputs from the form, and email them to myself.
However, I would like to send a separate email to the user after he/she submits the form. That email does not contain any form data, but only a message saying that their request is received and will be answered as soon as possible, etc.
As I am quite new to this area, could anybody advise what the simple script would be which allows the user to receive a separate email after completing and submitting a form.
I very appreciate your kind help.
Kindest regards
ikeen107
$body = qq¦
Name: $fname $lname <br>
Email:$customer_email <br>
Subject: $subject <br>
Message: $message <br>
¦;
Customize the headers, footer, etc:
$cust = qq¦
Dear $fname $lname, <br>
Thank you for visiting our site and here is a message you'll possibly never read, but it lets you know we're on it! :-)
$body
¦;
$co = qq¦
A customer visited your site on $thisTime and left the following message: <br>
$body
¦;
Create your MAIL procedure in a subroutine that accepts the to, from, subject, and message in that order:
&send_mail($customer_email,$company,$subject,$cust);
&send_mail($company,$customer_email,$subject,$co);
sub sendmail {
my ($to,$from,$sub,$msg) = (@_);
.......
}
Note in the call to send_mail, the first goes TO the customer, the second goes to the company.
You could just use the CC and BCC fields in the mail headers, but what fun is there in that? :-)
Thank you very much for your prompt help.
In your codes provided, where should I insert the form data in order to send them only to the company not to the customer. Basically, I downloaded a simple CGI code from a website, and modify to reflect my need. Here is my CGI codes:
#!/usr/bin/perl
# The following accepts the data from the form
if ($ENV{'REQUEST_METHOD'} eq 'POST') {
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/, $buffer);
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$FORM{$name} = $value;
}
# The following sends the email
open (MESSAGE,"¦ /usr/sbin/sendmail -t");
print MESSAGE "To: $FORM{emailAddr}\n";
print MESSAGE "To: $FORM{ourEmail}\n";
print MESSAGE "From: $FORM{emailAddr}\n";
print MESSAGE "Subject: Feeback for $FORM{fullName}\n\n";
if ($FORM{fullName}) { print MESSAGE "Name: $FORM{fullName}\n"; }
if ($FORM{address}) { print MESSAGE "Address: $FORM{address}\n"; }
if ($FORM{city}) { print MESSAGE "City: $FORM{city}\n"; }
if ($FORM{state}) { print MESSAGE "State/Prov.: $FORM{state}\n"; }
if ($FORM{country}) { print MESSAGE "Country: $FORM{country}\n"; }
if ($FORM{zip}) { print MESSAGE "Postal Code: $FORM{zip}\n"; }
if ($FORM{phoneNo}) { print MESSAGE "Phone: $FORM{phoneNo}\n"; }
if ($FORM{emailAddr}) { print MESSAGE "Email: $FORM{emailAddr}\n"; }
if ($FORM{areas}) { print MESSAGE "Property area: $FORM{areas}\n"; }
if ($FORM{byPhone}) { print MESSAGE "By phone: $FORM{byPhone}\n"; }
if ($FORM{byEmail}) { print MESSAGE "By email: $FORM{byEmail}\n"; }
if ($FORM{byPost}) { print MESSAGE "By post: $FORM{byPost}\n"; }
if ($FORM{byOther}) { print MESSAGE "By other: $FORM{byOther}\n"; }
print MESSAGE "Message:\n\n";
if ($FORM{message}) { print MESSAGE "$FORM{message}\n"; }
else { print MESSAGE "No message!\n"; }
close (MESSAGE);
&thank_you;
}
#The following creates the Thank You page display
sub thank_you {
print "Content-type: text/html\n\n";
print "<html>\n";
print "<head>\n";
print "<title>Thank You Page</title>\n";
#link to external style sheet file: style1.css
print "<link rel=\"StyleSheet\" name=\"style\" href=\"../styles/style.css\" type=\"text/css\">";
print "</head>\n";
print "<body bgcolor=#FFFFCC text=#000000>\n";
print "<h1><center>Invest Dubai Properties</center></h1><hr>";
print "<h2 align=\"center\">Thank You!</h2>\n";
print "\n";
print "<h3 align=center>Your message has been successfully sent!</h3><hr><br>";
print "<center><a class=\"declink\" href=\"../index.html\">Back to home page</a></center>\n";
print "</body>\n";
print "</html>\n";
exit(0);
}
The above code will send the same email to both customer and company.
I have very little knowledge of CGI/Perl. Please advise if I have to remove or modify the sending mail part (second part) of the code. Or I am very grateful, if you could provide me with a sample of the codes used to send separate emails to customer and company.
I do appreciate your help.
Regards