View Full Version : Form mailer problem

10-03-2009, 11:23 PM

I could do with a bit of help on a CGI script I'm writing. Here is the script:


use CGI;

my $query = new CGI;

print $query->header ( );

my $friends_name = $query->param("friends_name");
my $friends_email = $query->param("friends_email");
my $your_name = $query->param("your_name");

open ( MAIL, "| /usr/lib/sendmail -t" );
print MAIL "From: noreply\@simply-france.co.uk\n";
print MAIL "To: $friends_email\n";
print MAIL "Subject: La Maison des Tournesols (a suggestion from your friend $your_name)\n\n";
print MAIL "Your friend $your_name has suggested that you may be interested in staying at La Maison des Tournesols, a bed & breakfast close to Niort in France. For more details on this accommodation, please visit: http://www.simply-france.co.uk/tournesols/\n\n";
close ( MAIL );

print <<END_HTML;
<META HTTP-EQUIV="refresh" CONTENT="1;URL=http://www.simply-france.co.uk/tournesols/thanks.html">

It is being called from:

Basically, the line that is causing a problem is:

print MAIL "To: $friends_email\n";

This is somehow stopping the script from working. If I replace the $friends_email variable with a hard-coded email address, for example:

print MAIL "To: gary\@domain.co.uk\n";

...the script works fine, and sends an email to that email address.

What am I doing wrong?


10-03-2009, 11:36 PM
Have you tried to add this after the freinds_email address has been declared?

$friends_email =~ s/@/\\@/;

That makes the @ a \@



10-04-2009, 01:37 AM
You need to validate all user supplied form data. Don't rely solely on javascript validation.

The starting point to troubleshoot your problem would be to dump the vars (with Data::Dumper or one of its cousins) so you can see exactly what they hold. You also need to validate the submitted email address (with Email::Valid) to verify that it's a valid format.