Gossamer Forum
Home : General : Perl Programming :

sub to send a "thank you" via email

Quote Reply
sub to send a "thank you" via email
CGI Newbie Question 1293: I need to figure out how to make a sub in a cgi to send a "thank you" via email when data is submitted.

I want to be able to do this...

Code:
if ($log != 1) {
&submit("information was submitted.");
&thanks("thank you page.");
&send_thanks("sent thank you email.");
}
Code:

Any help will be appreciated.
Quote Reply
Re: [madtech] sub to send a "thank you" via email In reply to
Hi

Maybe you could try something like this?

Code:
if ($log != 1) {
&submit("information was submitted.");
&thanks("thank you page.");
&send_thanks($email,$name); # you'll need to pass email address and name here
}

sub send_thanks {

my ($email,$name) = @_;

open(MAIL,"|/usr/lib/sendmail -t");

print MAIL "To: $email\n";
print MAIL "From: your\@email.here (your name here)\n";

print MAIL "Subject: Thanks for that mate!\n\n";

print MAIL "Hey $name,\n\n";
print MAIL "Thanks for sending that link it! Nice one!\n";

close (MAIL);

}

- wil

Last edited by:

Wil: Dec 4, 2001, 7:00 AM
Quote Reply
Re: [Wil] sub to send a "thank you" via email In reply to
That will have to come before &thanks if the thanks sub is printing html
Quote Reply
Re: [PaulW] sub to send a "thank you" via email In reply to
Yeah? Why's that then?

- wil
Quote Reply
Re: [Wil] sub to send a "thank you" via email In reply to
Well it isn't essential but IMO is is better coding to have the html outputted as the last step. Seems a bit silly printing html and then sending an email.


Last edited by:

PaulW: Dec 4, 2001, 8:40 AM
Quote Reply
Re: [PaulW] sub to send a "thank you" via email In reply to
Ah right. Yes, I agree with you at that point. Or at least do some error checking before hand. If you output the HTML saying "Email sent" and then encounter an error opening your pipe you'll look a bit silly.

But the fastest solution would be; error_check, print_html, send_mail. ?

- wil
Quote Reply
Re: [PaulW] sub to send a "thank you" via email In reply to
Although on the other hand, if sendmail produces an error because of someone entering in a bad email address, you will get a 500 server error (as your headers have not been printed yet).

Cheers,

Alex
--
Gossamer Threads Inc.
Quote Reply
Re: [Wil] sub to send a "thank you" via email In reply to
Wil,

Code:
while(<CHECK>) {
($user,$pass,$mail) = split(/\|/,$_);
if ($input{'myuser'} eq $user) {
$log = 1;
}
}
close(CHECK);

if ($log != 1) {
&register("registration recorded.");
&send_thanks($email,$name); # you'll need to pass email address and name here
&thanks("thank you.");
}

I can't pass $user or $mail because those are from the database that I checked against, what I need to pass to the sub is the $input{'myuser'} and $input{'mymail'}. How would I do that? (Sorry for my ignorance.. I am learning)
Quote Reply
Re: [Alex] sub to send a "thank you" via email In reply to
Thats why you call an error routine with a header :)
Quote Reply
Re: [madtech] sub to send a "thank you" via email In reply to
No matter. I figured it out. Sometimes even the obvious is difficult to figure out when your learning cgi.

Here is what I had to do...

Code:
{
$reguser = $input{'myuser'};
$regmail = $input{'mymail'}
}

if ($log != 1) {
&register("user was registered.");
&send_thanks($reguser,$regmail);
&welcome("welcome.");
}

Next I have to figure out how to do error checking.

Thanks for your help.