Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Sending email, would like a success (or failure) page to display

by tonto (Friar)
on Jun 13, 2015 at 19:54 UTC ( [id://1130315]=perlquestion: print w/replies, xml ) Need Help??

tonto has asked for the wisdom of the Perl Monks concerning the following question:

I'm trying to use sendmail to send the contents of a webform to email. The script I've written gets the parameters from the webform (via post) and it does send the email but it always ends with an error. Here's a stripped-down version of my best try, it ends with an error about my use of Email::Sender::Success->success.

The "success" page is never displayed, if I could I'd like to also have a "failure" page.

use strict; use warnings; use CGI qw( :standard ); use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use Email::Simple; use Email::Sender::Simple qw(sendmail); use Email::Sender::Success; use Email::Simple::Creator; my $sender = param('Name'); my $sndr_email = param('Email'); my $sire1 = param('Sire1'); my $dam1 = param('Dam1'); my $sire2 = param('Sire2'); my $dam2 = param('Dam2'); my $rcp_email = "email\@gmail.com"; my $subject = "Mating"; my $message = "Combination 1:\nSire: $sire1\nDam: $dam1\n\nCombination +2:\nSire: $sire2\nDam: $dam2\n"; my $email = Email::Simple->create( header => [ From => "$sndr_email", To => "$rcp_email", Subject => "$ +subject" ], body => $message, ); sendmail($email); if (my $success = Email::Sender::Success->success) { #this is wrong print "Content-type: text/html\n\n"; #the page is never seen print << 'EOF'; <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:/ +/www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1 +" /> <title>Title</title> <link rel="stylesheet" type="text/css" href="cgistyle3.css" /> </head> <body> <div id="banner"><div id="links"> <a href="http://localhost/entrance/index.html">home</a> <a href="http://localhost/entrance/search.pl">search</a> </div></div> <hr /> <h3>The form has been sent!</h3> </body> </html> EOF } 1;

Replies are listed 'Best First'.
Re: Sending email, would like a success (or failure) page to display
by choroba (Cardinal) on Jun 13, 2015 at 20:04 UTC
    As the documentation says, the success object is returned from the sendmail subroutine.
    if (sendmail($email)) { # On success }

    Without success, the subroutine thows an exception, i.e. dies. Therefore, without evaling the subroutine (or using something like Try::Tiny), you don't have to check the success.

    if (eval { sendmail($email) }) { # On success... } else { # On failure }
    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      Thank you!

      I read the documentation but I didn't understand how to apply it, I am wiser now.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://1130315]
Approved by davido
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2025-11-17 03:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What's your view on AI coding assistants?





    Results (72 votes). Check out past polls.

    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.