Solved

Send HTML Formatted email with Perl

Posted on 2004-04-26
9
517 Views
Last Modified: 2008-03-10
I have a feeling this question has been asked before.  If it has been answered, feel free to direct me to the answer.  If not, here is the issue.  

My web site is remotely hosted, and I cannot install any extra packages.  It is linux w/ apache 1.3.26.  

I want to have a html form trigger two emails, one to me with an out put of the filled out forms (which was easy and finished), the other should be a nice, html-formatted email to the person who actually filled out the form.  The way I am doing this appears to not work.  I am using a semi-customized formmail (from Matts script archive) to do this.  Here's what I have tried:

sub respond_mail {
    # Localize variables used in this subroutine.                            #
    local($print_config,$key,$sort_order,$sorted_field,$env_report);

    # Open The Mail Program
    open(MAIL,"|$mailprog");

    print MAIL "To: $Form{'EmailAddress'}\n";
    print MAIL "From: $Config{'email'} ($Config{'realname'})\n";

    # Check for Message Subject
    print MAIL "Subject: Thank you\n\n";

    print MAIL "Content-type:text/html\n\n";
    print MAIL <<EndResponseHTML;

   <html code>

    EndResponseHTML
    close (MAIL);
}

I am a relative beginner to perl, so explanations are good, though examples are great.
0
Comment
Question by:jibip
  • 4
  • 3
  • 2
9 Comments
 
LVL 7

Expert Comment

by:glassd
ID: 10922919
What are you using to send the mail. Unless to tell mail to read the message header from the file, it will try reading from the command line. Using sendmail -t should work. Check the man page for sendmail or your preferred method.
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10922927
Some general points first:

1.  Do not touch the stuff at Matt's script archive.  They are poorly written, insecure and not maintained.  Use the equivalent versions from http://nms-sourceforge.net/

2.  If you can upload HTML files, then you *can* install a lot of the Perl modules.

Anyway, the standard answer is to use MIME::Lite for this sort of stuff.  It is *extremely* easy to install.  It just requires one file to be copied to your server.

See http://search.cpan.org/~yves/MIME-Lite-3.01/lib/MIME/Lite.pm for usage examples.
0
 
LVL 7

Accepted Solution

by:
glassd earned 125 total points
ID: 10922942
This is a segment used to send our standard system emails.

open (MAIL,"|/usr/lib/sendmail -t");
print MAIL "From: name\@company.com\n";
print MAIL "To: name\@somewherelse.com\n";
print MAIL "Subject: Some subject line\n";
print MAIL "MIME-Version: 1.1\n";
print MAIL "Content-type: text/html; charset=us-ascii\n";
print MAIL "<table width=\"80%\" border=\"0\" ";
print MAIL "cellspacing=\"0\" cellpadding=\"0\">";
print MAIL "<tr><td>";
print MAIL "<font face=\"verdana, Arial Black, Arial, Sans-serif\" ";
print MAIL "size=\"+4\" color=\"#aaaaaa\"> ";
print MAIL "<b>Title of Email</b></font><br>";
print MAIL "</td></tr></table>";
print MAIL "Rest of message\n";
close (MAIL);
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 

Author Comment

by:jibip
ID: 10922951
glassd, I am using sendmail

$mailprog = '/usr/lib/sendmail -i -t -f

I think you guys need to read a bit closer, my website is remotely hosted, therefore I can't install anything. I was also told that my version of formmail had been secured, and in fact it is locked to only send to and from specific email addresses, which I have control over.  

I'm not sure if you need other information, let me know.  
0
 

Author Comment

by:jibip
ID: 10922983
Can I use Per's ability to block html code like:

print MAIL <<EndHTML;

<html>
...
</html>

EndHTML


?
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10923220
If your website is remotely hosted, how do you update your webpages and how do you expect to modify the Perl script if you have no access.
0
 

Author Comment

by:jibip
ID: 10927815
I use ftp to upload new files to the web directories that I have permission to.  

I just meant I can't install new packages or anything like that.  
0
 

Author Comment

by:jibip
ID: 10928212
glassd,

thanks for the sample code.  looks like I had everything except for the:

print MAIL "MIME-Version: 1.1\n";

After adding this it appears that the emails are being sent.  I was also able to use the html block, to simplify the coding.  I'll give an official update later, after I do some more testing.  

Thanks
0
 
LVL 48

Expert Comment

by:Tintin
ID: 10933834
jibip.

You *can* install a lot of the Perl modules yourself.  If you can FTP a file, you can install a Perl module.

MIME::Lite is one of the easiest modules to install.  Just one file involved.
0

Featured Post

Does Powershell have you tied up in knots?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
pattern matching in perl 2 103
Perl script to parse xml file 2 111
Perl modules on linux ec2 3 104
Perl Frameworks 1 90
Many time we need to work with multiple files all together. If its windows system then we can use some GUI based editor to accomplish our task. But what if you are on putty or have only CLI(Command Line Interface) as an option to  edit your files. I…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question