With the AxKit::XSP::Sendmail taglib, it is very simple to send email from an XSP page. This taglib combines email-address verification, using the Email::Valid module, with email sending, using the Mail::Sendmail module (which will either interface to an SMTP server or use the sendmail executable directly). Again, to allow usage of this taglib, the following line must be added to httpd.conf:
AxAddXSPTaglib AxKit::XSP::Sendmail
Then sending email from XSP is as simple as what's shown in Example E-5.
<xsp:page
xmlns:xsp="http://apache.org/xsp/core/v1"
xmlns:param="http://attic.apache.org/projects/axkit.html/NS/xsp/param/v1"
xmlns:mail="http://attic.apache.org/projects/axkit.html/NS/xsp/sendmail/v1"
language="Perl"
>
<page>
<xsp:logic>
if (!<param:email/>) {
<p>You forgot to supply an email address!</p>
}
else {
my $to;
if (<param:subopt/> eq "sub") {
$to = "axkit-users-subscribe@axkit.org";
}
elsif (<param:subopt/> eq "unsub") {
$to = "axkit-users-unsubscribe@axkit.org";
}
<mail:send-mail>
<mail:from><param:user_email/></mail:from>
<mail:to><xsp:expr>$to</xsp:expr></mail:to>
<mail:body>
Subscribe or Unsubscribe <param:user_email/>
</mail:body>
</mail:send-mail>
<p>(un)subscription request sent</p>
}
</xsp:logic>
</page>
</xsp:page>
The only thing missing here is some sort of error handling. When the sendmail taglib detects an error (either in an email address or in sending the email), it throws an exception.
 
Continue to: