CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Sending Mail CGI/Perl/SQL

 



rmitchell12
New User

Jul 21, 2012, 2:35 PM

Post #1 of 1 (1414 views)
Sending Mail CGI/Perl/SQL Can't Post

I am selecting info from a database, making a string that makes an HTML page with the variables from the database included. Works fine, but I want to send that html source (which I have made $message) in an email. I cannot get it to send though. When I run the page it shows $message just like I want it, and if I change the message and don't include $message in the email, it will send an email. Any help would be greatly appreciated.

Edit: When I make the $message variable with $message = q( all the data) instead of 'qq', it will send the script fine, without the content of the variables, of course.

my $dbh = DBI->connect("allmyinfo")
or die "Couldn't connect to database: $DBI::errstr\n";

#select email addresses for all users
my $sql = "SELECT email FROM people";
my $sth = $dbh->prepare($sql);
$sth->execute;
while($data = $sth->fetchrow_hashref){
push (@emails, $data->{email});
push (@emails, ', ');
}


#select last 5 posts

my $sql = "SELECT name, id, content FROM posts ORDER BY id DESC
LIMIT 5";
my $sth = $dbh->prepare($sql);
$sth->execute;
while($data = $sth->fetchrow_hashref){
push (@theposts, $data->{name});
push (@thepostid, $data->{id});
push (@thecontent, $data->{content});

}

#select last 5 grant items

my $sql = "SELECT id, organization, city, giving FROM grants ORDER BY id DESC
LIMIT 5";
my $sth = $dbh->prepare($sql);
$sth->execute;
while($data = $sth->fetchrow_hashref){
push (@theid, $data->{id});
push (@thegrants, $data->{organization});
push (@thecity, $data->{city});
push (@thegiving, $data->{giving});

}

$dbh->disconnect;

#Get Date

my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
$year += 1900;
$mon += 1;
my $datetime = sprintf "%04d%02d%02d%02d%02d%02d", $year, $mon, $mday, $hour, $min, $sec;


my @abbr = qw( Jan Feb Mar Apr May Jun Jul August Sep Oct Nov Dec );

# $mon=9, $mday=18 gives "Oct 18th"





######Makes HTML source with variables from database
my $message = qq(
<!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'>

<head>
<style><!--
.hmmessage P
{
margin:0px;
padding:0px
}
body.hmmessage
{
font-size: 10pt;
font-family:calibri
}
--></style>
<body class='hmmessage'><div dir='ltr'>

<title>News from Non-Profit Insight</title>
<div id="ecxrootDiv" align="center">
<table style="background-color:#3C0B0B" bgcolor="#3C0B0B" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td rowspan="1" colspan="1" align="center" valign="top"><table style="width:600px" border="0" cellpadding="1" cellspacing="0" width="600">
<tbody><tr>
<td rowspan="1" colspan="1" align="left" valign="top" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td style="height:15px" rowspan="1" colspan="1" align="center" height="15" valign="top">
</td></tr>
</tbody></table></td>
</tr>
<tr>
<td style="background-color:#3C0B0B;padding:1px" rowspan="1" colspan="1" align="left" bgcolor="#3C0B0B" valign="top"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td style="background-color:#FFFFFF" rowspan="1" colspan="2" align="left" bgcolor="#FFFFFF" valign="top" width="100%"><table id="ecxcontent_LETTER.BLOCK2" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td style="text-align:left" rowspan="1" colspan="1" align="left"><img alt="NonProfit Insight - Your grant research resource" src="http://www.nonprofitinsight.com/img/mail_header.jpg" border="0" height="147" width="600"></td>
</tr>
</tbody></table></td>
</tr>
</tbody></table>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td style="background-color:#D5E9F5;width:150px;padding:5px" rowspan="1" colspan="1" align="center" bgcolor="#D5E9F5" valign="top" width="150"><table style="margin-bottom:5px" id="ecxcontent_LETTER.BLOCK3" border="0" cellpadding="5" cellspacing="0" width="100%">
<tbody><tr>
<td style="color:#332D74;font-family:Arial,Helvetica,sans-serif;font-size:10pt;text-align:left" rowspan="1" colspan="1" align="left"><div style="color:#000000;font-family:Arial Narrow,Arial MT Condensed Light,sans-serif;font-size:10pt"><br>
</div>
<br>
<div style="color:#332d74"><a style="color:rgb(51, 45, 116);text-decoration:underline;font-weight:bold" href="http://www.nonprofitinsight.com/" target="_blank">nonprofitinsight.com</a><br>
<br>
</div>
<div style="color:#332d74"><a style="color:rgb(51, 45, 116);text-decoration:underline" href="http://www.nonprofitinsight.com/pages/about_us/" target="_blank">About&nbsp;Us</a></div>
<div style="color:#332d74"><a style="color:rgb(51, 45, 116);text-decoration:underline" href="http://www.nonprofitinsight.com/pages/about_us/" target="_blank">Mission</a></div>
<div style="color:#332d74"><a style="color:rgb(51, 45, 116);text-decoration:underline" href="http://www.nonprofitinsight.com/pages/contact_us/" target="_blank">Contact Us</a></div>
<div style="color:#332d74"><a style="color:rgb(51, 45, 116);text-decoration:underline" href="http://www.nonprofitinsight.com/pages/become_a_member/" target="_blank">Membership</a>&nbsp;<br>
<br>
</div></td>
</tr>
</tbody></table>
</td>
<td style="background-color:#FFFFFF;width:450px;padding:5px" rowspan="1" colspan="1" align="left" bgcolor="#FFFFFF" valign="top" width="450"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td rowspan="1" colspan="1" align="left" width="100%"><table id="ecxcontent_LETTER.BLOCK6" border="0" cellpadding="5" cellspacing="0" width="100%">
<tbody><tr>
<td style="color:#666666;font-family:Arial Narrow,Arial MT Condensed Light,sans-serif;font-size:12pt;text-align:left" rowspan="1" colspan="1" align="left"></td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td rowspan="1" colspan="1" align="left" width="100%">


<h4 class="h4">Weekly Update - $abbr[$mon] $mday th $year </h4>

<hr style="height:1px;border:none;border-bottom:1px solid #ddd">

<h4 class="h4">Recent Blog Posts</h4>




<hr style="height:1px;border:none;border-bottom:1px solid #ddd">

<a href="http://www.nonprofitinsight.com/posts/view/@thepostid[0]" target="_blank"><strong>@theposts[0]</strong></a><BR>


<table cellspacing=0 cellpadding=0 width=100% height=80 border=0><tr><td height=80>

<div style="height: 80px;
width: 100%; overflow: hidden">

@thecontent[0]
</td></tr></table>

<a href="http://www.nonprofitinsight.com/posts/view/@thepostid[0]" target="_blank">Read more </a>
<BR>


<hr style="height:1px;border:none;border-bottom:1px solid #ddd">

<a href="http://www.nonprofitinsight.com/posts/view/@thepostid[1]" target="_blank"><strong>@theposts[1]</strong></a><BR>


<table cellspacing=0 cellpadding=0 width=100% height=80 border=0><tr><td height=80>

<div style="height: 80px;
width: 100%; overflow: hidden">

@thecontent[1]
</td></tr></table>

<a href="http://www.nonprofitinsight.com/posts/view/@thepostid[1]" target="_blank">Read more </a>
<BR>



<hr style="height:1px;border:none;border-bottom:1px solid #ddd">

<a href="http://www.nonprofitinsight.com/posts/view/@thepostid[2]" target="_blank"><strong>@theposts[2]</strong></a><BR>


<table cellspacing=0 cellpadding=0 width=100% height=80 border=0><tr><td height=80>

<div style="height: 80px;
width: 100%; overflow: hidden">

@thecontent[$number]
</td></tr></table>

<a href="http://www.nonprofitinsight.com/posts/view/@thepostid[2]" target="_blank">Read more </a>
<BR>



<hr style="height:1px;border:none;border-bottom:1px solid #ddd">

<a href="http://www.nonprofitinsight.com/posts/view/@thepostid[3]" target="_blank"><strong>@theposts[3]</strong></a><BR>


<table cellspacing=0 cellpadding=0 width=100% height=80 border=0><tr><td height=80>

<div style="height: 80px;
width: 100%; overflow: hidden">

@thecontent[3]
</td></tr></table>

<a href="http://www.nonprofitinsight.com/posts/view/@thepostid[3]" target="_blank">Read more </a>
<BR>


<hr style="height:1px;border:none;border-bottom:1px solid #ddd">

<a href="http://www.nonprofitinsight.com/posts/view/@thepostid[4]" target="_blank"><strong>@theposts[4]</strong></a><BR>


<table cellspacing=0 cellpadding=0 width=100% height=80 border=0><tr><td height=80>

<div style="height: 80px;
width: 100%; overflow: hidden">

@thecontent[4]
</td></tr></table>

<a href="http://www.nonprofitinsight.com/posts/view/@thepostid[4]" target="_blank">Read more </a>
<BR>



<h4 class="h4">Recent Grants</h4><hr style="height:1px;border:none;border-bottom:1px solid #ddd">

<strong>Company</strong>: <a href="http://www.nonprofitinsight.com/app/webroot/index.php/grants/view/@theid[0]" target="_blank">@thegrants[0] </a><BR>
<strong>Location</strong>: @thecity[0]<BR>
<strong>Giving</strong>: @thegiving[0]<BR><BR>
<strong>Company</strong>: <a href="http://www.nonprofitinsight.com/app/webroot/index.php/grants/view/@theid[1]" target="_blank">@thegrants[1] </a><BR>
<strong>Location</strong>: @thecity[1]<BR>
<strong>Giving</strong>: @thegiving[1]<BR><BR>
<strong>Company</strong>: <a href="http://www.nonprofitinsight.com/app/webroot/index.php/grants/view/@theid[2]" target="_blank">@thegrants[2] </a><BR>
<strong>Location</strong>: @thecity[2]<BR>
<strong>Giving</strong>: @thegiving[2]<BR><BR>
<strong>Company</strong>: <a href="http://www.nonprofitinsight.com/app/webroot/index.php/grants/view/@theid[3]" target="_blank">@thegrants[3] </a><BR>
<strong>Location</strong>: @thecity[3]<BR>
<strong>Giving</strong>: @thegiving[3]<BR><BR>
<strong>Company</strong>: <a href="http://www.nonprofitinsight.com/app/webroot/index.php/grants/view/@theid[4]" target="_blank">@thegrants[4] </a><BR>
<strong>Location</strong>: @thecity[4]<BR>
<strong>Giving</strong>: @thegiving[$4]

<BR>
<hr style="height:1px;border:none;border-bottom:1px solid #ddd">



<table style="background-color:#999999" bgcolor="#999999" border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td rowspan="1" colspan="1" align="left" height="1">
</td></tr>
</tbody></table></td>
</tr>
<tr>
<td rowspan="1" colspan="1" align="left" valign="top" width="100%"><table style="margin-bottom:5px" border="0" cellpadding="10" cellspacing="0" width="100%">
<tbody><tr>
<td style="color:#555555;font-family:Arial,Helvetica,sans-serif;font-size:10pt" rowspan="1" colspan="1" align="left">
<div>&nbsp;</div>
<div>For assistance, comments or questions call <B>(417) 496-5897</b><Br> or visit <a href="http://www.nonprofitinsight.com">www.nonprofitinsight.com</a><BR><BR>
<B>Thank you for subscribing.</b></div>
</td>
</tr>
</tbody></table></td>
</tr>
</tbody></table></td>
</tr>
</tbody></table></td>
</tr>
<tr>
<td rowspan="1" colspan="1" align="left" height="10" width="100%"><table border="0" cellpadding="0" cellspacing="0" width="100%">
<tbody><tr>
<td style="height:15px" rowspan="1" colspan="1" align="center" height="15" valign="top">
</td></tr>
</tbody></table></td>
</tr>
</tbody></table></td>
</tr>
</tbody> </table>
</div></div> </div></body></html>);

#send email

my $from = "noreply\@nonprofitinsight.com";
my $subject = 'this';

my $sendmail = '/usr/lib/sendmail';
open(MAIL, "|$sendmail -oi -t");
print MAIL "From: $from\n";
print MAIL "To: robert\@businessinnovationsmo.com\n";
print MAIL "Subject: test\n";
print MAIL "$message";
close(MAIL);

print header;
print "$message";

Code


	

(This post was edited by rmitchell12 on Jul 21, 2012, 4:00 PM)

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives