Hi. I'm trying to use a newsletter script and am having a problem with the send letter file. This script works from a mysql database and all other functions work correctly. The problem is that I get a Notice: Undefined index: email in /usr/home/websites/visit/admin/sendletter.php on line 25. Line 25 is this line: $email = $r['email'];. I cannot for the life of me figure out the problem. Can anyone here see a possible cause?
Here is the sendletter.php:
<?php
error_reporting(E_ALL);
// set time limit to 15 minutes (900/60)
set_time_limit(900);
include("connect.php");
$id = preg_replace("/'\/<>\"/","",$_GET['id']);
if (empty($id))
die("Invalid ID");
$link = "SELECT * FROM newsletters WHERE id='$id'";
$res = mysql_query($link) or die(mysql_error());
$r = mysql_fetch_assoc($res);
$subject = $r['name'];
$message = $r['content'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: newsletter@' . $_SERVER['SERVER_NAME'] . "\r\n" .
'Reply-To: newsletter@' . $_SERVER['SERVER_NAME'] . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$link = "SELECT * FROM users WHERE status='subscribed'";
$res = mysql_query($link) or die(mysql_error());
while ($r = mysql_fetch_row($res))
{
$email = $r['email'];
$mail = mail($email, $subject, $message, $headers);
}
if ($mail)
{
echo "Email sent to " . $email . '<br>';
die;
}
else
{
echo "Error in mailing " . $email . '<br>';
die;
}
?>
Thanks!