Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    6
    Thanked 0 Times in 0 Posts

    adding data to body of email being sent?

    So I was having the problem with the CGI script sending an email which has now been resolved.... but now another question.

    I want to have some data that is coming from the form that is being submitted to be put into the body of the email being sent. I have a 'state1' & 'state2' but I would also want more then just that data being read when it goes to the cgi script. Here is the code again and you will see where I was trying to add the users first name and also state1 but it doesn't work on either one. I will also be adding multiple lines for the body of the email since I would like to have the following to be in the body (state1 & state2, 2 citys to go with each state, contact for the poster, price and possibly one other)

    Other then that the script is working perfectly.


    Code:
    #!/usr/bin/perl
    
    #use strict;
    use warnings;
    use CGI::Carp qw(fatalsToBrowser carpout);
    use CGI qw(:standard);
    use DBD::mysql;
    use LWP::Simple;
    use URI;
    print "Content-type: text/html \n\n";
    
     ###############################
     # find the root if this is IIS:
     ###############################
     if($ENV{'SERVER_SOFTWARE'} =~ m/IIS/)
     {
    	if($root eq "" && $ENV{'PATH_TRANSLATED'} ne "")
    	{
    		my $pt = $ENV{'PATH_TRANSLATED'};
    		my @pts = split(/\\/, $pt);
    		$pts[-1] = "";
    		$root = join "/", @pts;
    		$OS = "NT";
    	}
     }
    
     ###############################
     # functions library:
     ###############################
     if(!$dontparse){
            require "${root}data/config/pmpre.cfg";
            require "${root}lib/mysql.lib";
            require "${root}lib/pm.lib";
            require "${root}lib/phpbb.lib" if($plugin_phpbb eq "yes");
     }
    
     ###############################
     # Read the data coming from the form..
     ###############################
     if(!$dontparse){ &readit; }
     ###############################
    
      if($use_cookie eq "yes" && !$dontparse && $input{'ID'}<1 && $input{'action'} ne "register"){
       #- retrieve existing cookie
       $lp = $req->cookie("pmpre");
       my ($clogin, $cID) = split(/\|/, pm_decode($lp));
       if(($clogin ne "") and ($cID ne "")){
    	   if($input{'login'} eq ""){
    		$input{'login'} = $clogin;
    	   }
    	   if($input{'ID'} eq "" && $input{'password'} eq ""){
    		$input{'ID'} = $cID;
    	   }
       }
    
     }
    
    
    my $count = 0;
    #my $subject = "New posting in your Location";
    my $flag = "1";
    #my $from2 = "admin";
    my $time = &get_time;
    my $sendmail = "/usr/sbin/sendmail -t";
    
    $query = "SELECT MAX(mailno) FROM `mailbox`";
    my $sth = $dbh->prepare($query);
    $sth->execute();
    my ($data) = $sth->fetchrow_array();
    my $mailno = ($data + 1);
    
    
    my $departures_sth = $dbh->prepare("SELECT * FROM `departures`
                                     WHERE `departures_states` = ?
                                     AND `departures_state_region` = ?" )
                            or die $DBI::errstr;
    
    $departures_sth->execute($input{'state1'}, $input{'state2'}) or die $DBI::errstr;
    
    while( my $departures = $departures_sth->fetchrow_hashref ){
        my $firstname = $departures->{'departures_email_2'};
        my $login = $departures->{'login'};
        my $to = $departures->{'departures_email'} || die "no email retrieved from db";
        my $origin = $departures->{'departures_states'};
    $count = ($count + 1);
    
    
    
       # if these are the same for each email,
       # then they should be declared prior to the while loop
        my $from = 'notify-DONOTREPLY@domain.com';
        my $subject = 'New posting in your location';
        my $body = 'Hi "$firstname", testing location email "$state1"';
        
        my $header = <<"HEADER";
    To: $to
    From: $from
    Subject: $subject
    Content-type: text/html
    
    HEADER
     
        print "attempting to send email:<br>",
              "$header$body<br>";
    
        open(MAIL, "|$sendmail") or die "Can't pipe $sendmail: $!\n";
        print(MAIL "$header$body");
        close(MAIL);
    }
    
    $departures_sth->finish;
    
    print "<br>$count ";
    
    	if ($count == 1){
    	print "Member has";
    	} else {
    	print "members have";
    	}
    
    print " been alerted about this post..<br><br>";
    
    exit;

  • #2
    New Coder
    Join Date
    Oct 2009
    Posts
    70
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Ok, so I figured out that I needed " instead of ' on the my $body line for it to work.

    Now, I am putting all of my email body info on 1 line with <br> code to have a break... is that the best way or how do I have multiple lines for the body?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •