Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Email Formatting

by b310 (Scribe)
on Mar 29, 2005 at 19:54 UTC ( [id://443239]=perlquestion: print w/replies, xml ) Need Help??

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

Hello:

I wrote a subroutine which sends an email with the information that was sent via a registration form.

Is there a way that I can format the body of my email message so it looks more readable?

Here's is the body of the email in the subroutine:
Member Name: $name Member ID: $memberid Telephone: $phone Email Address: $email Guest Name(s): $guest Event Date: $eventdate Events: $event Payment: $payment Message: $message

Is there a way that I can format the above into a two column table? Right now, my results appear as a sentence and it is difficult to read. Is it also possible to bold any of the text?

Thank you for any help in advance.

I'm including the entire subroutine in case you need to see the all the code.

sub send_confirmation_email { my %mail = ( From => "pperry1\@comcast.net", # YOU SHOULD CHANGE THI +S! To => $email, Subject => "Event Registration Form Submitted", Message => "" ); my $page; $mail{Message} = <<EOF; Thank you for your inquiry. A tennis staff member will reply to you w +ithin 24 hours. This is the information you submitted. Member Name: $name Member ID: $memberid Telephone: $phone Email Address: $email Guest Name(s): $guest Event Date: $eventdate Events: $event Payment: $payment Message: $message EOF sendmail (%mail) or $page .= p (escapeHTML ("Oops, failure sending mail to $mai +l{To}")); return (defined ($page) ? $page : ""); } #@ SEND_CONFIRMATION_EMAIL

Replies are listed 'Best First'.
Re: Email Formatting
by ambs (Pilgrim) on Mar 29, 2005 at 19:57 UTC
    Some suggestions: Text::Template can be used to define a layout. Text::Format let you format your text.

    Hope this can be helpful.

    Alberto Simões

Re: Email Formatting
by The Mad Hatter (Priest) on Mar 29, 2005 at 20:45 UTC
    And if you really want a true two column table, use Text::Table; I love it for formatting stuff.
      Hello:

      Thank you for your reply.

      It sounds like Text::Table is exactly for what I'm looking. My hosting provider does not have this module installed on the server.

      Do you know how I can install it on the server?

      Thank you in advance.
Re: Email Formatting
by cazz (Pilgrim) on Mar 29, 2005 at 20:11 UTC
Re: Email Formatting
by jhourcle (Prior) on Mar 30, 2005 at 03:56 UTC

    If you want the text to line up in columns, is there any reason why you don't have the stuff in the message lined up?

    Member Name: $name Member ID: $memberid Telephone: $phone Email Address: $email Guest Name(s): $guest Event Date: $eventdate Events: $event Payment: $payment Message: $message

    or

    Member Name: $name Member ID: $memberid Telephone: $phone Email Address: $email Guest Name(s): $guest Event Date: $eventdate Events: $event Payment: $payment Message: $message

    Of course, you'd want to make sure that all of the stuff was properly wrapped if it was too long of a string, etc. But if those items are verified to be short, it's not a problem. (I'm assuming $message isn't.... for that, look at format and write)

    Installing new modules just for this simple task would be overkill, if the builtin stuff meets the needs, in my opinion.

    And um... as you said 'provider'. I hope this isn't for a web page. If it is, return a webpage -- sending to email addresses that were entered on a web page is just asking for trouble.

      Hello:

      Thank you for your reply. As you suggested, I tried lining up the text into columns. Actually, I tried both of the formats you suggested. Neither of them worked

      I did some reading on the format link you sent me and it seems that might just be the answer.

      My question, do I place the format code within the body of my email or do I have to do it in the beginning of my script.

      Thank you in advance for your help.
      Hello:

      I tried the format which you provided to me as a link to read on.

      When I run my script, I receive the following message:
      Global symbol "$text" requires explicit package name

      Here is the what I did with the code:
      #@ SEND_CONFIRMATION_EMAIL sub send_confirmation_email { my %mail = ( From => "info\@summitwebcrafters.com", # YOU SHOULD CHA +NGE THIS! To => $email, Subject => "Junior Program Registration Form Submitted", Message => "" ); my $page; $mail{Message} = <<EOF; Thank you for your inquiry. A tennis staff member will reply to you w +ithin 24 hours. This is the information you submitted. $text = "$name\n$memberid\n$phone"; format STDOUT = Text: ^* $text ~~ ^* $text . EOF sendmail (%mail) or $page .= p (escapeHTML ("Oops, failure sending mail to $mai +l{To}")); return (defined ($page) ? $page : ""); } #@ SEND_CONFIRMATION_EMAIL


      Any ideas of what I did wrong? Thank you for any help in advance.

        When you're working under use strict; (which is a good thing), you need to let Perl know when you're starting the use of a new variable, by declaring it with my or our, or using use vars. In your case, the problem is actually more subtle, as you're using <<EOF which tells Perl that what follows is to be a string until it sees EOF on a line by itself.

        You'll also need to move the format call to whatever is sending the message to the sendmail. (as it works on filehandles... see the documentation on write ... I apologize, as I probably should have explained it better -- (if we compare 'write' to 'printf', there's no function equivalent to a 'write' version of 'sprintf' that I know of))

        However, I'm more surprised that you said that lining up the text in the code didn't result in them being lined up in the e-mail. It's possible that the sendmail() function that you're using may be corrupting something, or not sending the message as plain text. If so, no matter how much work you do to get it looking pretty as plain text, something else is mangling it.

Re: Email Formatting
by gam3 (Curate) on Mar 30, 2005 at 03:47 UTC
    If you want to bold text you will need to use html (or some other fancy format). If you send it as a Content-Type: multipart/alternative; Then you can have it both as text and html and the recipient can look at in the the format that is best for them.

    I think that MIME::Lite will be of help, along with CGI.

    -- gam3
    A picture is worth a thousand words, but takes 200K.
      Howdy!

      -- for suggesting HTML clutter.

      He wants to send it as email. That implies plain text, where "font", "color", "bold", etc. are foreign concepts. HTML markup has no place in email.

      Call me a dinosaur, but don't call me "got viruses from email".

      yours,
      Michael

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others browsing the Monastery: (7)
As of 2024-04-18 11:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found