帮我从群发邮件 php 脚本中删除订阅者

发布于 2024-10-12 07:02:23 字数 7157 浏览 8 评论 0原文

我需要找到一种方法从群发邮件 php 脚本中删除订阅者 这是脚本:

<?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){
   if (!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>';
  }
 }
}

?>

谢谢

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']?>" />   <?php echo $i18n['OR']; ?>   <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){
   if (!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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

蝶舞 2024-10-19 07:02:23

圣钼。

您应该能够通过记事本或任何其他文本编辑器编辑创建的 other/massmail.xml 文件。

如果您希望以编程方式编辑它(不是真正的单词),我相信您可以使用 SimpleXMLExtended 类循环遍历每个 XML 节点(如代码中所示)。如果可能,您应该考虑逐节点读取它,这样整个文件就不会加载到内存中。

附注:我强烈建议不要使用 XML 来存储邮件列表。如果您使用 MySQL 等数据库(如果您坚持将其存储在文件中,则使用 SQLite),管理起来会更容易、更高效。

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).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文