Search code examples
perlcgimailto

PERL CGI mailto does not work


I have a web report written in PERL CGI. It pulls some constantly changing data from a flat-file DB and displays the current status in a table on the web page. I want to be able to click a link that will push all of that data into an email that can be edited before sending.

This is what I have as my last chunk of HTML on the page. The "Go To Status" link works but the mailto:xxx@xx.com link causes server errors. Does "mailto" not work in a CGI script for some reason? It gets rendered as HTMl so I'm not sure why it wouldn't.

sub EndHtml {
   print "<P align=right> <a href='http://www.xxx.com/~a0868183/cgi-bin/xxx.cgi'>Go to Status</a> </p>\n";
   print "<p align=right> <a href='mailto:xxx@xx.com'></a>Send EOS</p>\n";
   print "</BODY></HTML>\n";
}

(Once I figure this out I will then put the variables with the data into the email)

Thanks, Jared


Solution

  • @ has special meaning in a double quote delimited string.

    Always start your script with:

    use strict;
    use warnings;
    

    Then you will get alerted (if you read your log files):

    Possible unintended interpolation of @xx in string
    

    Then you can escape it:

    mailto:xxx\@xx.com
    

    Or use a single quoted string:

    print q{<p align=right> <a href='mailto:xxx@xx.com'></a>Send EOS</p>\n};
    

    Or don't embed your HTML in the middle of your Perl and use a Template language (like Template Toolkit).


    You probably want to put some content in the anchor too.