rendered paste body<?php
$config = './config.php';
if( file_exists( $config ) )
{
if( is_readable( $config ) )
{
require( $config );
}
else
{
die( "Cannot read config file" );
}
}
else
{
die( "Cannot find config file" );
}
checkAdminLogin();
if( !isset( $_GET[ 'user_id' ] ) )
{
die( 'Error: no user_id' );
}
ignore_user_abort( true );
set_time_limit( 0 );
$return_message = '';
$no_message_error = '';
$no_subject_error = '';
if( isset( $_POST[ 'launch_mailing' ] ) )
{
$error = false;
if( !strlen( $_POST[ 'message' ] ) )
{
$error = true;
$no_message_error = 'Please include a message';
}
if( !strlen( $_POST[ 'subject' ] ) )
{
$error = true;
$no_subject_error = 'Please include a subject';
}
$subject = stripslashes( $_POST[ 'subject' ] );
$message = stripslashes( $_POST[ 'message' ] );
$unsub_key = md5( time() );
$html_unsubscribe = <<<EOF
<br><br>
<a href="$GLOBALS[SITE_BASE_URL]/u.php?k=$unsub_key">Click Here To Unsubscribe</a>
<br><br>
EOF;
$text_unsubscribe = "\r\n\r\nUnsubscribe: $GLOBALS[SITE_BASE_URL]/u.php?k=$unsub_key\r\n\r\n";
$headers = <<<EOF
From: $SITE_OWNER_NAME <$GLOBALS[SITE_OWNER_EMAIL]>
X-Sender: <$GLOBALS[SITE_OWNER_EMAIL]>
Return-Path: <$GLOBALS[SITE_OWNER_EMAIL]>
Error-To: <$GLOBALS[SITE_OWNER_EMAIL]>
X-Mailer: $_SERVER[SERVER_NAME]
EOF;
if( isset( $_POST[ 'message_type' ] ) && $_POST[ 'message_type' ] == 'html' )
{
$headers .= <<<EOF
MIME-Version: 1.0
Content-type: text/html; charset=iso-8859-1
EOF;
}
$headers .= "\r\n";
if( !$error )
{
if( isset( $_POST[ 'signoff' ] ) && $_POST[ 'signoff' ] == 'yes' )
{
if( isset( $_POST[ 'unsubscribe_link' ] )
&& $_POST[ 'unsubscribe_link' ] == 'yes' )
{
if( $_POST[ 'message_type' ] == 'html' )
{
$message .= $html_unsubscribe;
}
else
{
$message .= $text_unsubscribe;
}
}
if( mail( $GLOBALS[ 'SITE_OWNER_EMAIL' ],
$subject,
$message,
$headers ) )
{
$return_message = 'Test Message Sent';
}
else
{
$return_message = 'Test Message NOT sent, mail() returned FALSE.. check your setup.';
}
}
if( isset( $_POST[ 'signoff' ] ) && $_POST[ 'signoff' ] == 'no' )
{
$and = '';
if( isset( $_POST[ 'subscribed' ] )
&& $_POST[ 'subscribed' ] != 'all' )
{
$and .= "
AND $GLOBALS[TB_USERS].subscribed = '$_POST[subscribed]'
";
}
$sql = "
SELECT
email,
first_name,
last_name,
subscribed,
email_valid
FROM $GLOBALS[TB_USERS]
WHERE user_id = '$_GET[user_id]'
";
$query = sqlQuery( $sql );
if( sqlNumRows( $query ) )
{
$no_mail = 0;
$succeeded = 0;
$array = sqlFetchArray( $query );
$do_not_email = false;
if( isset( $_POST[ 'image_status' ] )
&& $_POST[ 'image_status' ] != 'all' )
{
$images_count = getUserImagesCount( $array[ 'user_id' ], 'approved' );
if( $_POST[ 'image_status' ] == 'no' && $images_count )
{
$do_not_email = true;
}
if( $_POST[ 'image_status' ] == 'some' && !$images_count)
{
$do_not_email = true;
}
}
if( isset( $_POST[ 'subscribed' ] )
&& $_POST[ 'subscribed' ] != 'all' )
{
if( $array[ 'subscribed' ] == 'n' )
{
$do_not_email = true;
}
if( $array[ 'email_valid' ] == 'n' )
{
$do_not_email = true;
}
}
if( !$do_not_email )
{
$unsub_key = getUserKey( $_GET[ 'user_id' ], 'unsub_key' );
$html_unsubscribe = <<<EOF
<br /><br />
<a href="$SITE_BASE_URL/u.php?k=$unsub_key">Click Here To Unsubscribe</a>
<br /><br />
EOF;
$text_unsubscribe = "\r\n\r\nUnsubscribe: $GLOBALS[SITE_BASE_URL]/u.php?k=$unsub_key\r\n\r\n";
if( isset( $_POST[ 'unsubscribe_link' ] )
&& $_POST[ 'unsubscribe_link' ] == 'yes' )
{
if( $_POST[ 'message_type' ] == 'html' )
{
$message .= $html_unsubscribe;
}
else
{
$message .= $text_unsubscribe;
}
}
if( mail( $array[ 'email' ], $subject, $message, $headers ) )
{
$succeeded++;
}
}
else
{
$no_mail++;
}
$failed = sqlNumRows( $query ) - $succeeded - $no_mail;
$return_message = "$succeeded email sent<br>$failed failed to send<br>";
}
else
{
$return_message = "No email was sent, your query returned zero rows..<br>";
}
}
}
else
{
$return_message = 'Errors were encountered.. no email was sent';
}
}
$subject = isset( $_POST[ 'subject' ] )
? htmlentities( stripslashes( $_POST[ 'subject' ] ) )
: '';
$message = isset( $_POST[ 'message' ] )
? htmlentities( stripslashes( $_POST[ 'message' ] ) )
: '';
$plain_text_checked = isset( $_POST[ 'message_type' ] )
&& $_POST[ 'message_type' ] == 'plain_text'
? ' checked'
: '';
$html_checked = isset( $_POST[ 'message_type' ] )
&& $_POST[ 'message_type' ] == 'html'
? ' checked'
: '';
if( !strlen( $plain_text_checked) && !strlen( $html_checked ) )
{
$plain_text_checked = ' checked';
}
$unsub_checked = isset( $_POST[ 'unsubscribe_link' ] )
&& $_POST[ 'unsubscribe_link' ] == 'yes'
? ' checked'
: '';
$unsub_not_checked = isset( $_POST[ 'unsubscribe_link' ] )
&& $_POST[ 'unsubscribe_link' ] == 'no'
? ' checked'
: '';
if( !$unsub_checked && !$unsub_not_checked )
{
$unsub_checked = " checked";
}
$sql = "
SELECT
email,
first_name,
last_name
FROM $GLOBALS[TB_USERS]
";
$query = sqlQuery( $sql );
if( sqlNumRows( $query ) )
{
$array = sqlFetchArray( $query );
}
$FinalHTML .= <<<EOF
<html>
<head>
<title></title>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="style.css" type="text/css" >
</head>
<body bgcolor="#eeeeee" background="bg.gif">
<table cellpadding="3" cellspacing="0" border="0">
<form method="post" action="mailUser.php?user_id=$_GET[user_id]">
<tr class="alt1">
<td colspan="2" class="bold">Email $array[first_name] $array[last_name]</td>
</tr>
<tr class="alt2">
<td class="text" colspan="2" align="center"><span class="error">$return_message</span></td>
</tr>
<tr class="alt2">
<td class="text" align="right">To:</td><td class="text">$array[first_name] $array[last_name] <$array[email]></td>
</tr>
<tr class="alt2">
<td class="text" align="right">From:</td><td class="text">$GLOBALS[SITE_OWNER_NAME] <$GLOBALS[SITE_OWNER_EMAIL]></td>
</tr>
<tr class="alt2">
<td class="text" align="right">Subject:</td><td class="text"><input class="input" type="text" name="subject" size="55" value="$subject"><br><span class="error">$no_subject_error</span></td>
</tr>
<tr class="alt2">
<td class="text" align="right">Message:</td><td class="text"><textarea class="input" name="message" rows="10" cols="55">$message</textarea><br><span class="error">$no_message_error</span></td>
</tr>
<tr class="alt2">
<td class="text" align="right">Message Type:</td><td class="text"><input class="input" type="radio" name="message_type" value="plain_text"$plain_text_checked> Plain Text<br><input class="input" type="radio" name="message_type" value="html"$html_checked> HTML</td>
</tr>
<tr class="alt2">
<td class="text" align="right">Unsubscribe Link:</td><td class="text"><input class="input" type="radio" name="unsubscribe_link" value="yes"$unsub_checked> Yes<br><input class="input" type="radio" name="unsubscribe_link" value="no"$unsub_not_checked> No</td>
</tr>
<tr class="alt2">
<td class="text" align="right">Signoff:</td><td class="text"><input class="input" type="radio" name="signoff" value="yes" checked> Test Mode (send me a test email only)<br><input class="input" type="radio" name="signoff" value="no"> Real Mailing (I'm sure, do it!)</td>
</tr>
<tr class="alt2">
<td class="text" colspan="2" align="right"><span class="error">(Click once and wait)</span> <input class="button" type="submit" name="launch_mailing" value="Launch Mailing ->"><br></td>
</tr>
</form>
</table>
</body>
</html>
EOF;
echo cleanFinalOutput( $FinalHTML );
?>