WordPress Custom newsletter subscribe

add_action(‘admin_menu’, ‘subscriber_menu’);

function subscriber_menu(){
add_menu_page( ‘Subscriber Menu Page’, ‘Subscriber Mail’, ‘manage_options’, ‘subscriber-menu’, ‘subscriber_init’ );
}

function subscriber_init(){
?>
<div class=”subs”>
<?php if($_POST[‘submit’]==’send’)
{ ?>
<?php //print_r($_POST);
global $wpdb;
$user=$_POST[‘user’];
$subject=$_POST[‘subject’];
$message=$_POST[‘message’];
$headers = “From: ” . strip_tags($_POST[‘sender’]) . “\r\n”;
$headers .= “MIME-Version: 1.0\r\n”;
$headers .= “Content-Type: text/html; charset=ISO-8859-1\r\n”;
$res = $wpdb->get_results( “SELECT user_id FROM `wp_bizzworks`.`wp_bp_xprofile_data` WHERE (CONVERT(`id` USING utf8) LIKE ‘%$user%’ OR CONVERT(`field_id` USING utf8) LIKE ‘%$user%’ OR CONVERT(`user_id` USING utf8) LIKE ‘%$user%’ OR CONVERT(`value` USING utf8) LIKE ‘%$user%’ OR CONVERT(`last_updated` USING utf8) LIKE ‘%$user%’)”, OBJECT );
//echo “<pre>”;print_r($res->user_id);echo “</pre>”;
//echo  “SELECT user_id FROM `wp_bizzworks`.`wp_bp_xprofile_data` WHERE (CONVERT(`id` USING utf8) LIKE ‘%$user%’ OR CONVERT(`field_id` USING utf8) LIKE ‘%$user%’ OR CONVERT(`user_id` USING utf8) LIKE ‘%$user%’ OR CONVERT(`value` USING utf8) LIKE ‘%Member%’ OR CONVERT(`last_updated` USING utf8) LIKE ‘%$user%’)”;
foreach($res as $row)
{

//echo “<pre>”; print_r($row->user_id); echo “</pre>”;

$useremail=$wpdb->get_row( “SELECT value FROM wp_bp_xprofile_data WHERE user_id='”.$row->user_id.”‘ AND field_id = ’10’ “);

if($useremail->value==”)
{
$userdata=get_userdata( $row->user_id);
$emailaddress = $userdata->data->user_email;
}
else
{
$emailaddress = $useremail->value;
}
//echo “<pre>”;print_r($emailaddress);echo “<pre>”;
$mail=wp_mail( $emailaddress, $subject, $message, $headers, $attachments );

}
if($mail)
{
echo ‘Mail Successfully Send’;
}
else{
echo ‘Mail Sending failed’;
}
?>
<?php } ?>
<form method=”post” action=””>
<div class=”subswrap”>
<label for=”sender” id=”sender” class=”subs-text”>Sender Email:</label>
<input type=”text” autocomplete=”off” id=”Sender” value=”” size=”30″ name=”Sender”>
</div>
<div class=”subswrap”>
<label for=”subject” id=”subject” class=”subs-text”>Subject :</label>
<input type=”text” autocomplete=”off” id=”subject” value=”” size=”30″ name=”subject”>
</div>
<div class=”subswrap”>
<label for=”usertype” id=”type” class=”subs-text”>User Type :</label>
<span>
<select name=”user”>
<option value=”Staff” selected=”selected”>Staff</option>
<option value=”Member” >Member</option>
</select>
</span>
</div>
<div class=”subswrap”>
<label for=”message” id=”message” class=”subs-text”>Message :</label>
<textarea type=”text” autocomplete=”off” id=”message” value=”” cols=”50″ rows=”10″ name=”message”></textarea>
</div>
<div class=”send”>
<input type=”submit” value=”send” name=”submit” class=”button button-primary”>
</div>
</form>

</div>
<?php } ?>

<style>

.subs {
padding: 30px;
}.subs > div {
padding: 10px;
}
.subs-text {
float: left;
vertical-align: top;
width: 120px;
}

.subswrap {
margin-bottom: 10px;
}
.send {
margin-left: 9.1em;
}
</style>

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s