...

View Full Version : adding data to body of email being sent?



awayne96
01-06-2010, 08:10 AM
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.



#!/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;

awayne96
01-06-2010, 08:55 AM
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?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum