Hi All,
I have a somewhat simple problem but it is still a problem.
I have this html newsletter that must go out every month to all th members, same as any other website, but mine doesnt want to display properly on the clients mail.
For the first memeber its fina and displays perfectly, but for the second, it adds the first members newsletter, and son on for the third etc. What am I doing wrong, I have tried and not conquered. Please help.
Then I think I have to send it as an attachment for mailclients that isnt set up for email, what do I do to get that right as well.
Below is all the code for the page. Just if anyone spots any errors in my code elsewhere. Thanks a mil.
$q = "SELECT * FROM member WHERE newsletter = 1";
if (!$result = mysql_query($q, $link))
die('Could not retrieve member listings. Big Problems! Contact administrator. ' . mysql_error() );
echo $q;
?>
<?php
//this loops through the whole page for every member that has subscribed to the newsletter
for ($i=0;$row=mysql_fetch_array($result);$i++)
{
$body .= '
<html>
<head>
<title>
newsletter
</title>
</head>
<body >
<table align="left" border=0 cellpadding=8 cellspacing=1>
<tr>
<td align="left" valign="top"><img src="newsletTemplTop.gif" width="550" height="186"></td>
</tr>
<tr>
<td><p>Dear ' . ucfirst($row['2']) . ' ' . ucfirst($row['3']) . '<br></p></td>
</tr>
<tr>
<td><p>Here is our monthly newsletter. Portrayed in this is the latest need to knows that you have subscribed to.</p></td>
</tr>';
//this checks if the member has subscribed to the news subject and prints accordingly
if ($row['news'] == 1)
{
$a = mysql_query("SELECT MAX(news_ID) FROM news");
$b = mysql_fetch_row($a);
$query = "SELECT * FROM news WHERE news_active = 1 AND news_ID BETWEEN " . ($b['0'] - 4) . " AND " . $b['0'];
if (!$res = mysql_query($query, $link))
die (" Could not get last news posts for newsletter. ");
$body .= '
<tr>
<th colspan="5"><p>Latest News:</p></th>
</tr>';
for ($i=0;$r=mysql_fetch_array($res);$i++) {
$body .= '<tr>
<tr>
<th width="74%">' . $r['1'] . '</th>
<th width="26%">Date Posted: ' . date("j M y", strtotime($r['5'])) . '</th>
</tr>
<tr>
<td colspan="2">' . $r['2'] . '</td>
</tr>
<tr>
<td colspan="2">' . $r['3'] . '</td>
</tr>
<tr>
<td colspan="2"><a href="http://www.francesbaarddm.gov.za/content.php?pageID=newsinfo"">Read more about this here...</a></p></td>
</tr>
<tr><td colspan="4"><hr></td></tr>
</tr>
';
}
}
else {}
//this is the format for events and checks whether member has selected this option
if ($row['events'] == 1)
{
$a = mysql_query("SELECT MAX(events_ID) FROM events");
$b = mysql_fetch_row($a);
$query = "SELECT * FROM events WHERE events_active = 1 AND events_ID BETWEEN " . ($b['0'] - 4) . " AND " . $b['0'];
if (!$res = mysql_query($query, $link))
die (" Could not get last events posts for newsletter. ");
echo $query;
$body .= '
<tr>
<th colspan="4"><p>Latest Events:</p></th>
</tr>';
for ($i=0;$r=mysql_fetch_array($res);$i++) {
$body .= '<tr>
<tr>
<th width="74%">' . $r['1'] . '</th>
<th width="26%">Date Posted: ' . date("j M y", strtotime($r['5'])) . '</th>
</tr>
<tr>
<td colspan="2">' . $r['2'] . '</td>
</tr>
<tr>
<td colspan="2">' . $r['3'] . '</td>
</tr>
<tr>
<td colspan="2"><a href="http://www.francesbaarddm.gov.za/content.php?pageID=newsinfo"">Read more about this here...</a></p></td>
</tr>
<tr><td colspan="4"><hr></td></tr>
</tr>
';
}
}
else {}
//this is the format for jobs and checks whether member has selected this option
if ($row['jobs'] == 1)
{
$a = mysql_query("SELECT MAX(jobs_ID) FROM jobs");
$b = mysql_fetch_row($a);
$query = "SELECT * FROM jobs WHERE jobs_active = 1 AND jobs_ID BETWEEN " . ($b['0'] - 4) . " AND " . $b['0'];
if (!$res = mysql_query($query, $link))
die (" Could not get last jobs posts for newsletter. ");
$body .= '
<tr>
<th colspan="4"><p>Latest Jobs:</p></th>
</tr>';
for ($i=0;$r=mysql_fetch_array($res);$i++) {
$body .= '<tr>
<tr>
<th width="74%">' . $r['1'] . '</th>
<th width="26%">Date Posted: ' . date("j M y", strtotime($r['5'])) . '</th>
</tr>
<tr>
<td colspan="2">' . $r['2'] . '</td>
</tr>
<tr>
<td colspan="2">' . $r['3'] . '</td>
</tr>
<tr>
<td colspan="2"><a href="http://www.francesbaarddm.gov.za/content.php?pageID=newsinfo"">Read more about this here...</a></p></td>
</tr>
<tr><td colspan="4"><hr></td></tr>
</tr>
';
}
}
else {}
if ($row['calendar_updates'] == 1)
{
$body .= '<tr>
<tr>
<th colspan="4"><p>This needs work still</p></th>
</tr>
<tr><td colspan="4"><hr></td></tr>
</tr>
';
}
else {}
$body .='
</table>
';
$mime_boundary = "<<<--==+X[".md5(time())."]";
$headers = "From: info@fbdm.co.za\r\n";
$headers .= "Return-Path: info@fbdm.co.za\r\n";
$headers .= "X-Sender: info@fbdm.co.za\r\n";
$headers .= "X-Mailer: Website\r\n";
$headers .= "Organization: Frances Baard District Municipality\r\n";
$headers .= "Bcc: " . $row['email'] . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed;\r\n";
$headers .= " boundary=\"".$mime_boundary."\"";
$message .= "This is a multi-part message in MIME format.\r\n";
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";
$message .= "Content-Type: text/html; \r\n";
$message .= "Content-Transfer-Encoding: 8bit\r\n";
$message .= "\r\n";
$message .= $body . "\n";
$message .= "--".$mime_boundary."\r\n";
/
$message .= "Content-Type: text/html;\r\n";
$message .= "Content-Transfer-Encoding: 8bit\r\n";
$message .= "\r\n";
$message .= $body;
$message .= "\r\n";
$message .= "--".$mime_boundary."\r\n";
/
//$to = $row['email'] . "\r\n";
$mailsent = mail($to, "FBDM Newsletter", $message, $headers);
}
echo $body;
if ($mailsent)
{
$query = "INSERT INTO newsletter VALUES (NULL, 'newsletter no " . (mysql_insert_id + 1) . "', NOW())";
if (!mysql_query($query, $link))
die('Could not save quote listing. Contact administrator. ' . mysql_error() );
print ("Email sent.");
}
else
print ("Could not send email");
?>