![]() |
Practical mod_perl / HTML Book / | ![]() |
||
![]() |
||||
![]() |
![]() |
|||
![]() |
![]() |
|||
![]() |
||||
|
|
||||
![]() |
![]() |
|||
![]() |
E.3.3. Sending Email |
![]() |
||
![]() |
||||
![]() |
![]() |
![]() |
||
![]() |
||||
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://axkit.org/NS/xsp/param/v1"
xmlns:mail="http://axkit.org/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:
mod_perl, modperl, Apache, perl, cgi, html, mod_perl, e-commerce, scalability, free, open source, OSS, apache, squid, high availability, modperl, linux, unix, Web, www, mod_perl, webserver, admin, apache, book, webmaster, tools, modperl, guide, docs, documentation, help, mod_perl, perl, information, apache, script, errata, eric cholet, perl, apache, mod-perl, stas bekman, mod_perl, cool, perl, Apache, performance, speed, choice
![]() |
Other projects to check out: meta-religion.com is for those interested in Religious, Spiritual and Esoteric Phenomena. i-want-a-better.com is a community of people discussing what they would like to be improved in their lives and things they use and interact with. You may also want to find a healer in your area or read articles on variety of topics.