开发者

Help me to remove subscriber from mass mail php script

开发者 https://www.devze.com 2023-02-04 03:38 出处:网络
i need to find a way to remove subscribers from mass mail php script here is script: <?php $thisfile=basename(__FILE__, \".php\");

i need to find a way to remove subscribers from mass mail php script here is script:

<?php

$thisfile=basename(__FILE__, ".php");

$path = GSPLUGINPATH.'gs_massmail/lang/';
$filenames = getFiles($path);
foreach ($filenames as $file) {
 if($file == $LANG.'.php')
  $language_file = $file;
}

if($language_file == FALSE)
 $language_file = 'en_US.php';

require_once $path.$language_file;

add_action('plugins-sidebar','createSideMenu',array($thisfile, 'Mass Mail'));

function get_mass_mail_form(){
 global $i18n;
?>
 <form action="<?php get_page_url(); ?>" method="post" class="contactform" >
  <?php set_mass_mail_page(); ?>
  <p>
   <input type="text" class="text" name="massmail[email]" value="e-mail" onFocus="doClear(this)" onBlur="doDefault(this)" />
  </p>
  <p><input type="submit" class="submit" value="<?php echo $i18n['MM_SUBSCRIBE']?>" id="add-receiver" name="add-receiver" /></p>
 </form> 
<?php
}

function show_editor(){
 global $i18n, $HTMLEDITOR;
 ?>
  <h3><?php echo $i18n['MM_SENDMAIL']?></h3>
  <form method="post" class="sendmassmail">
   <p>
    <b><?php echo $i18n['MM_SUBJECT']?></b>
    <br />
    <input type="text" id="subject" name="subject" size="70"/>
   </p>
   <p>
    <textarea id="post-content" rel="<?php echo $i18n['LABEL_PAGEBODY']; ?>" name="post-content"></textarea>
   </p> 
   <p><input class="submit" type="submit" name="submitted" value="<?php echo $i18n['MM_SENDMAILTOALL']?>" /> &nbsp;&nbsp;<?php echo $i18n['OR']; ?>&nbsp;&nbsp; <a class="cancel" href="pages.php?cancel"><?php echo $i18n['CANCEL']; ?></a></p>
  </form>

  <?php 
   if (defined('GSEDITORHEIGHT')) { $EDHEIGHT = GSEDITORHEIGHT .'px'; } else { $EDHEIGHT = '500px'; }
   if (defined('GSEDITORLANG')) { $EDLANG = GSEDITORLANG; } else { $EDLANG = 'en'; }
   if (defined('GSEDITORTOOL')) { $EDTOOL = GSEDITORTOOL; } else { $EDTOOL = 'basic'; }


   if ($EDTOOL == 'advanced') {
    $toolbar = "
      ['Bold', 'Italic', 'Underline', 'NumberedList', 'BulletedList', 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock', 'Table', 'TextColor', 'BGColor', 'Link', 'Unlink', 'Image', 'RemoveFormat', 'Source'],
           '/',
           ['Styles','Format','Font','FontSize']
       ";
   } else {
    $toolbar = "['Bold', 'Italic', 'Underline', 'NumberedList', 'BulletedList', 'JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock', 'Link', 'Unlink', 'Image', 'RemoveFormat', 'Source']";
   }
  ?>
  <?php if ($HTMLEDITOR != '') { ?>
  <script type="text/javascript" src="template/js/ckeditor/ckeditor.js"></script>
  <script type="text/javascript">
   var editor = CKEDITOR.replace('post-content', {
          skin : 'getsimple',
          forcePasteAsPlainText : true,
          language : '<?php echo $EDLANG; ?>',
          defaultLanguage : '<?php echo $EDLANG; ?>',
          entities : true,
          uiColor : '#FFFFFF',
    height: '<?php echo $EDHEIGHT; ?>', 
          toolbar : 
          [
          <?php echo $toolbar; ?>
    ]
          //filebrowserBrowseUrl : '/browser/browse.php',
          //filebrowserImageBrowseUrl : '/browser/browse.php?type=Images',
          //filebrowserWindowWidth : '640',
          //filebrowserWindowHeight : '480'
      });
  </script>
  <?php 
  }
}


function setup_mass_mail(){
  global $emailadresses;
  global $_POST, $i, $b, $i18n;

  $xmlfile = GSDATAPATH."other/massmail.xml";
  set_mass_mail_css();
  $v = getXML($xmlfile);

  if(isset($_POST['submitted'])){
   if(strlen($_POST['subject']) == 0 || strlen($_POST['post-content']) == 0)
    $err[] = $i18n['MM_SUBJECTANDMESSAGE'];

   if(count($err) == 0){
    echo "<h3>".$i18n['MM_EMAILSTATUS']."</h3>";
    $server_name = getenv ("SERVER_NAME");       // Server Name
    $request_uri = getenv ("REQUEST_URI");       // Requested URI

    $from = 'noreply@'.substr($server_name, 4, strlen($server_name));

    if(isset($_POST['subject']))
     $subject = $_POST['subject']; //htmlentities($_POST['subject'], ENT_QUOTES, 'UTF-8');
    else
     $subject = $i18n['MM_NEWSLETTERFROM'].$server_name;

    $headers = "From: ".$from."\r\n";
    $headers .= "Return-Path: ".$from."\r\n";
    $headers .= "Content-type: text/html\r\n";

    if(get_magic_quotes_gpc())
     $body = stripslashes($_POST['post-content']); //htmlentities($_POST['post-content'], ENT_QUOTES, 'UTF-8');
    else
     $body = $_POST['post-content'];

    foreach ($v as $row => $value) {
     if(mail($value->email,$subject,$body,$headers))
      $i++;
     else
      $b++;
    }   
    echo '<p class="ok">'.$i18n['MM_MAILWASSENTTO'].' ('.$i.' '.$i18n['MM_OF'].' '.($b+$i).')<p>';
   } else {
    echo '<p class="error">'.implode(".<br />", $err).'</p>';
   }
  }
  echo "<h3>".$i18n['MM_SUBSCRIBERS']."</h3>";
  if(file_exists($xmlfile) ) { 
   echo '<table cellspacing="0" cellpadding="0">
     <tr>
      <td>
      '.$i18n['MM_DATE'].'
      </td>
      <td>
      '.$i18n['MM_EMAIL'].'
      </td>
     </tr>
   ';
   foreach ($v as $row => $value) {
    $emailadresses .= $value->email.';';
    echo '<tr>';
     echo '<td>'.date('Y-m-d', (int)$value->date).'</td>';
     echo '<td>'.$value->email.'</td>';
    echo '</tr>';
   }
   echo '</table>';
   echo '<p><b>'.$i18n['MM_COMMASEPARATED'].':</b> <br />'.$emailadresses;
   show_editor();
  } else {
   echo $i18n['MM_NOREGSUBSCRIBERS'];
  }
}

function set_mass_mail_css(){
 echo '
 <!-- CSS for Mass Mail plugin -->
 <style type="text/css">
  p.ok {
   color: #3dc32b;
  }
  p.error {
   color: #FF0000;
  }
 </style>';
}

function set_mass_mail_page(){
 global $email;
 global $i18n;
 if (isset($_POST['add-receiver'])) {
  set_mass_mail_css();
  $xmlfile = GSDATAPATH."other/massmail.xml";
  $email = $_POST['massmail']['email'];
  $err = array();

  if(!check_email_address($_POST['massmail']['email'])){
   $err[] = $i18n['MM_EMAILWRONGFORMAT'];
  } else {
   if(file_exists($xmlfile) ) { 
    $v = getXML($xmlfile);
    foreach ($v as $row) {
     if($row->email == $_POST['massmail']['email']){
      $err[] = $i18n['MM_EMAILALLREADYREG'];
      break;
     }
    }
   }    
  }

  if(count($err) == 0){
   i开发者_开发知识库f (!file_exists($xmlfile) ) { 
    $xml = @new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><item></item>');
   } else {   
    $xmldata = file_get_contents($xmlfile);
    $xml = new SimpleXMLExtended($xmldata);
   }
   $thislog = $xml->addChild('entry');
   $thislog->addChild('date', time());
   $thislog->addChild('email', $email);
   $xml->asXML($xmlfile);
   echo '<p class="ok">'.$i18n['MM_YOUARENOWSUBSCRIBER'].'</p>';
  } else {
   echo '<p class="error">'.implode(".<br />", $err).'</p>';
  }
 }
}

?>

thanks


Holy moly.

You should be able to edit the other/massmail.xml file that this creates via Notepad or any other text editor.

If you wish to edit it programmitcally (not really word), I believe you can loop through each XML node using the SimpleXMLExtended class (as shown in your code). If possible, you should consider reading it node by node so the whole file isn't loaded into memory.

As a side note: I strongly recommend not using XML for storing a mailing list. It'd be much easier and more efficient to manage if you used a database such as MySQL (or SQLite if you insist on storing it in a file).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号