Gossamer Forum
Home : General : Internet Technologies :

PHP Mailing List Question

Quote Reply
PHP Mailing List Question
I am trying to make it so that when I send out a newsletter to an recipient contained in a list in my database, the email has a link at the bottom which contains the receivers email address for easy removal purposes. When I do this, I'm getting the included removal part repeated for each person who is in that database. This is because of my while statement, yet I don't see why it's doing this. I will give an example of what is received at the end of this code.

Code:


<html>
<head>
<title>Present Truth Administration :: Mailing List</title>
</head>
<body>


<?php if ($message_action=="Preview") {

$eMessage = stripslashes($_POST['eMessage']);


echo("<p>" . $eSubject . " " . $eMessage . "</p>");

} elseif ($message_action=="Post") {

$eMessage = stripslashes($_POST['eMessage']);

echo("<p>" . $eSubject . " " . $eMessage . "</p>");

// Default page display
// Connect to the database server
$dbcnx = @mysql_connect("localhost", "root");
if (!$dbcnx) {
echo( "<p>Unable to connect to the " .
"database server at this time.</p>" );
exit();
}

// Select the presenttruth database
if (! @mysql_select_db("presenttruth") ) {
echo( "<p>Unable to locate the note " .
"database at this time.</p>" );
exit();
}

// Update newsletter date.
$date = date('F dS Y.');

$news_date = @mysql_query("UPDATE news_date SET date = '$date' WHERE ID = '1'");

if (!$news_date) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}


echo("<h1> Addresses: </h1>");

// Request the ID, Address.
$list = @mysql_query("SELECT ID, Address FROM maillist");

if (!$list) {
echo("<p>Error performing query: " . mysql_error() . "</p>");
exit();
}


$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 1\r\n";
$headers .= "X-MSMail-Priority: High\r\n";


// Display Menu
while ( $row = mysql_fetch_array($list) ) {
$AddressID = $row["ID"];
$eAddress = $row["Address"];

$removal = "<h4 style='font-size: 10; font-family: verdana; font-weight: normal'>You are receiving this email because you have signed up to the Present Truth mailing list. If you would like to be removed, please click <a style='font-size: 10' href='http://presenttruth.dyndns.org/removemail.php?email=$eAddress'>here</a>. Thanks! - presenttruth.dyndns.org admin.</h4>";


$complete_message .= $eMessage;
$complete_message .= $removal;


echo("<a style='bold'>" . $eAddress . "</a> - SENT<br />");

mail("joshuarivard@shaw.ca", "$eSubject", "$complete_message", "$headers");
}


} else {
?>


<form action="<?=$PHP_SELF?>" method='post'>
<h4>Email Subject:<br />
<textarea name="eSubject" rows="1" cols="40" wrap></textarea><br />
<h4>Email Body:</br>
<textarea name="eMessage" rows="20" cols="60" wrap></textarea><br />
<input type="submit" name="message_action" value="Post" />
<input type="submit" name="message_action" value="Preview" /></h4>
</form>


<?php
}
?>


</body>
</html>


The following details are "Subject: Test; Body: test" Please notice that it starts going through the addresses contained in the database but is cut off after the two and a bit.

Quote:


test You are receiving this email because you have signed up to the Present Truth mailing list. If you would like to be removed, please click here. Thanks! - presenttruth.dyndns.org admin.

test You are receiving this email because you have signed up to the Present Truth mailing list. If you would like to be removed, please click here. Thanks! - presenttruth.dyndns.org admin.

test You are receiving this email because you have signed up to the Present Truth mailing list. If you would like to be removed, please click <a style='font-size: 10' href='http://pres


Any help is appreciated, not expected.
Quote Reply
Re: [JoFrRi] PHP Mailing List Question In reply to
Someone helped me with this already. If anyone cares to know what the answer to this was, it was I had to clear the variable "$complete_message" inside of the while statement.



Code:


// Display Menu
while ( $row = mysql_fetch_array($list) ) {
$AddressID = $row["ID"];
$eAddress = $row["Address"];

$removal = "...removal info...";

$complete_message .= $eMessage;
$complete_message .= $removal;

echo("<a style='bold'>" . $eAddress . "</a> - SENT<br />");

mail("$eAddress", "$eSubject", "$complete_message", "$headers");

$complete_message = '';
}