in reply to Re: emailing with an address taken from a database
in thread emailing with an address taken from a database

This line:

$Email_address eq $four;
should read:
$Email_address = $four;
eq is for string comparison. = is used for all scalar assignments.

I'd also add error checking to the open call:

open (FILE, "$data") or die "Failed to open $data: $!\n";

You need to find some way to see debugging output. The original code had debug statements going to the browser. Do those work? If so, I'd start adding some debugging so you can get an idea where things are going wrong. It will be hard to pinpoint without the ability to debug.

Replies are listed 'Best First'.
Re: Re: Re: emailing with an address taken from a database
by jonnyfolk (Vicar) on Feb 11, 2003 at 14:34 UTC
    Darn it! I had the $Email_address = $four; and then changed it just before posting - thanks for pointing it out.

    I tried adding debugging and just inserted a print "Email_address"; further down the script and decided I would get rid of the subroutine element and the (check=) statements just to try to simplify it.
    Immediately I received an email generated from the script! Progress, but it comes with befuddlement!!. what I have now is:
    #!/usr/bin/perl -w use strict; use CGI; my $query = new CGI; my $thisurl = "http://www.my_site.com/cgi-bin/email.pl"; my $id_in=$query->param('id_in'); my $Guest_Email=$query->param('Guest_Email'); my $check=$query->param('check'); my $Email_address; my ($Password,$U_Timestamp,$three,$four,$skipthisfield); my @emailer = (); my $data="/path/data/edit/data.txt"; open (FILE, "$data"); while (my $line =<FILE>) { ($Password,$U_Timestamp,$three,$four,$skipthisfield) = split "\t", +$line; if ($id_in eq $three) { $Email_address = $four; last; } } print "Content-type: text/html\n\n"; my $sendmailer; my $emailto; my $emailfrom; my $message_no; my $message; $sendmailer="/usr/sbin/sendmail"; $emailto="$Email_address"; $emailfrom="enquiry\@my_site.com"; print "Email is: $Email_address"; open (MAIL, "| $sendmailer -t") || die "sendmailer: $!"; print MAIL "To: $emailto\n"; print MAIL "From: $emailfrom\n"; print MAIL "Subject: Request for information\n"; print MAIL "Content-type: text/html\n\n"; print MAIL "<html><body><p>\n"; print MAIL "<font size=\"2\" color=\"#CC0000\">\n"; print MAIL "<u>REQUEST FOR INFORMATION</u><BR><BR>\n"; print MAIL "I am interested in receiving information on : $id_in<BR>\n +"; print MAIL "blah\n"; print MAIL "Any other comments:<BR>\n"; print MAIL "$message<br>\n"; print MAIL "</font></body></html>\n"; last; close(MAIL); close(MAIL);
    Any ideas why it should work like that but not in the previous version? (At least this gives me a basis to start looking but there might be something obvious which I'm not getting).
      Well, I have done some research, and the whole script works well including if (check=0) conditionals provided the sub routine aspect is removed! I don't know why. Perhaps someone could tell me?

      Thanks for the input so far