Gossamer Forum
Home : Products : DBMan : Customization :

Email if checked?

Quote Reply
Email if checked?
Hi all, I have a form page with couple of fields and 2 radiobuttons called "Yes" "No". What I wanted to do is, when someone modifies a record, and selects the "Yes" option, I wanted to send a email, but however if "No" is selected, it should just update the record in the database without sending an email. Is this possible? If so, please anybody help me.
Thanks
Quote Reply
Re: [shiva] Email if checked? In reply to
Check out LoisC's unofficial faq... sign up for an account and log-in, then look under "Email" for more options than you can imagine. I think what you need is there, or at least one of the existing mods can be adapted:

Here is the url http://webmagic.hypermart.net/...bfaq.cgi?db=dbmanfaq

Look for the one about "emailing admin when a record is modified" I think it can be changed to fit your needs.
Quote Reply
Re: [Watts] Email if checked? In reply to
Hi Watts, I have tried what you said. But it does not email me anything. Here is my code...

html.pl
sub html_modify_success

if($Approved eq "Yes"){
foreach $recipient (@mail_recipient) {
open (MAIL, "$mailprog") or &cgierr("unable to open mail program");
print MAIL "To: $recipient\n";
print MAIL "From: $admin_email\n";
print MAIL "Subject: Approval Code at $html_title\n\n";
print MAIL "Your are approved!:\n\n";
}

print MAIL "\n\n";
close MAIL;
}

I have the "Approved" field in my default.cfg and it's a "Yes" "No" radio button.
I have tried the same code without putting the if statement for emailing when a new record added and that seems to work fine. Any suggestions?
Thanks

Quote Reply
Re: [shiva] Email if checked? In reply to
How do you determine who to send the email to? Is the email address supplied somehow?

Here is what I use under "html_modify_success". Add something like following (the part in red) at the end of the subroutine before the closing bracket:

</body>
</html>
|;


if ($in{'Approved'} eq "Yes") {

####Sends E-mail #########
$mailprog = "/usr/sbin/sendmail"; # Sendmail Location
$youremail = "yourname\@yourdomain.com"; # Your Email Address
$ccmail = "someone-else\@anotherdomain.com"; # Send a carbon copy

####Begin Email Message ########

open (MAIL, "|$mailprog -oi -t") or die;
print MAIL "To:$youremail\n";
print MAIL "CC:$ccmail\n";
print MAIL "From:$youremail\n";
print MAIL "Subject: Confirmation\n";
print MAIL "MIME-Version: 1.0\n";
print MAIL "Content-Type: text/html; charset=us-ascii\n";
print MAIL "Content-Transfer-Encoding: 7bit\n";

print MAIL qq|
<HTML><BODY>
Put body of email message here in HTML format (if desired) and you can print fields out of the record too $rec{'fieldname'}, etc.
</BODY></HTML>
|;
close MAIL;
}

}


Now, the question is where you want to send the email... where does the email address come from? If entered on the page being modified everytime and not a permanent part of the record you'd use
$in{'EmailAddress'}. If it's part of the record (ie, saved in the database, or a hidden field), you'd use $rec{'EmailAddress'} in the print MAIL "To:$youremail\n"; part otherwise you'd just be sending the email to yourself from yourself. If you want a copy put your address in the carbon copy slot.

Last edited by:

Watts: Feb 11, 2003, 2:13 PM
Quote Reply
Re: [Watts] Email if checked? In reply to
Thanks Watts! It works perfect now. The only problem was in the if statement. Instead of the "in" i just just used "$Approved". The recepients were already defined in my default.cfg. Thanks again!
Quote Reply
Re: [shiva] Email if checked? In reply to
You may want to change:

>>
open (MAIL, "|$mailprog -oi -t") or die;
<<

to...

>>
open (MAIL, "|$mailprog -oi -t") or die "Can't start $mailprog: $!";
<<

...to give a useful error message.