Ir para conteúdo
Fórum Script Brasil
  • 0

Ajuda Com Newsletter


sorocabaunderground

Pergunta

eu tenho esse codigo e envia newsletter em pacotes de 10 em 10 com um tempo de 10 segundos

<?php 
include"../func/autentica.php";
require("../func/conn.php");

//configurações do e-mail 
$subject = "teste newsletter em pacotes"; 
$body = "testando um script de envio de newsletter em pacotes usando php e mysql"; 
$nome_remetente = "vinicius"; 
$email_remetente = "vinamsn@gmail.com"; 
$quant = 10; //número de mensagens enviadas de cada vez 
$sec = 10; //tempo entre o envio de um pacote e outro (em segundos) 
$pedido="SELECT (MAX(txtStatus)) AS txtStatus FROM tbemail";
$pega=mysql_query($pedido)or die (mysql_error());
while($rs_PegaCliente = mysql_fetch_array($pega)) {
$status = $rs_PegaCliente ['txtStatus'];
}
?>
<?php 
$ok = 0; 
$inicio = 0; 
$fim = $inicio + $quant; ?> 
<?php 
$sql = "SELECT * From tbemail WHERE txtStatus='0' LIMIT $inicio,$fim"; 
$query = mysql_query($sql,$conexao); 
$registros = mysql_num_rows($query); ?> 
<?php 
if($registros==0){ mysql_query("update tbemail set txtStatus = '1'"); 
printf("<font face=’tahoma’>todas as mensagens foram enviadas!</font>"); 
$ok = 1; } ?> 
<?php while($result = mysql_fetch_array($query)){ 
$id = $result[0]; 
$to = $result[1]; 
$status = $result[2]; 
$headers = "From: $nome_remetente <$email_remetente>"; 
mail($to,$subject,$body,$headers); mysql_query("update tbemail set txtStatus = '1' where IdEmail = $id"); 
printf("<font face=’tahoma’>$id ) mensagem para <b>$to</b> <font color=’#ff0000’><b>enviada com sucesso!</b></font></font> "); 
} 
?>
<?php 
mysql_free_result($query); mysql_close($conexao); 
?> 
<?php if(!$ok){ 
echo("<meta http-equiv=\"refresh\" content=\"" . $sec . "\">"); 
} 
?>

o grande problema que eu tenho é

quando ele envia para os 10 ele muda o status de 0 para 1

para saberda onde ele parou

so que c eu quiser enviar novos email o status vai esta 1 e não vai enviar

eu queria ver

como posso zerar o status denovo apos enviar, e que ele não começe a enviar denovo os e-mails pois o status volto a zero =P

obrigado

Link para o comentário
Compartilhar em outros sites

3 respostass a esta questão

Posts Recomendados

  • 0

cara...desculpa a demora...é que esqueci...mas está aí!


<?php
/**
 * E-Mail class
 *
 * <p>RFCS:</p>
 * <pre>
 * {@link http://www.rfc-editor.org/rfc/rfc2822.txt RFC2822} - Mail headers and body formatting
 * </pre>
 *
 * @author Sérgio Surkamp <sergio@empreendedor.com.br>
 * @package util
 */
/**
 * E-Mail class
 *
 * <p>RFCS:</p>
 * <pre>
 * {@link http://www.rfc-editor.org/rfc/rfc2822.txt RFC2822} - Mail headers and body formatting
 * </pre>
 *
 * @author Sérgio Surkamp <sergio@empreendedor.com.br>
 * @version 1.0.2
 * @package util
 * @todo Implement the priority level system
 * @todo Implement and test the CC and BCC system
 * @todo Implement attachFromFile method
 * @todo Implement external mimetype class
 * @todo Implement external charset class
 * @todo Rewrite the {@link Mail::send()} method
 */
class Mail
{
    /**
     * @var array $to Array of recipments
     */
    private $to = array();
    /**
     * @var array $cc Array of mail Carbon Copy
     */
    private $cc = array();
    /**
     * @var array $bcc Array of mail Blind Carbon Copy
     */
    private $bcc = array();
    /**
     * @var array $file Array of files
     */
    private $file = array();
    /**
     * @var string $fromEmail Email from...
     */
    private $from = null;
    /**
     * @var string $fromStr String for the mail from...
     */
    private $fromString = null;
    /**
     * @var string $subject Mail subject
     */
    private $subject = null;
    /**
     * @var string $message Mail message
     */
    private $message = null;
    /**
     * @var string $contentType Mime of the content type
     */
    private $contentType = Mail::MIME_TEXT_HTML;
    /**
     * @var string $charset Character set
     */
    private $charset = 'ISO-8859-1';
    /**
     * @var int $priority Mail priority
     */
    private $priority = Mail::PRIORITY_NORMAL;
    /**#@+
     * Constante
     */
    const MIME_TEXT_HTML = 'text/html';
    const MIME_TEXT_PLAIN = 'text/plain';
    const MIME_MULTIPART_MIXED = 'multipart/mixed';
    const MIME_MULTIPART_ALTERNATIVE = 'multipart/alternative';

    const PRIORITY_HIGHEST = 1;
    const PRIORITY_HIGH = 2;
    const PRIORITY_NORMAL = 3;
    const PRIORITY_LOW = 4;
    const PRIORITY_LOWEST = 5;
    /**#@-*/
    
    /**
     * Construtor
     *
     * @author Sérgio Surkamp <sergio@empreendedor.com.br>
     * @since 1.0.0
     * @param string $from String of the from mail
     * @param array $to Array of recipments
     * @param string $subject Message subject
     * @param string $message Message
     * @param string $fromString String for the from mail
     * @param array $cc Array of copy
     * @param array $bcc Array of back copy
     */
    function __construct($from, $to, $subject, $message, $fromString = null, $cc = null, $bcc = null)
    {
        $this->from = $from;
        $this->fromString = $fromString;
        $this->subject = $subject;
        $this->message = $message;
        if( is_array($to) )
        {
            $this->to = $to;
        }
        else
        {
            $this->to[] = $to;
        }
        if( is_array($cc) )
        {
            $this->cc = $cc;
        }
        if( is_array($bcc) )
        {
            $this->bcc = $bcc;
        }
    }
    /**
     * Attach a file
     *
     * @author Sérgio Surkamp <sergio@empreendedor.com.br>
     * @since 1.0.0
     * @param string $filename Filename
     * @param mixed $data File data
     * @param string $mime Mimetype
     */
    public function attachFile($filename, $data, $mime)
    {
        $this->file[] = array( 'filename'=>$filename, 'data'=>$data, 'mime'=>$mime );
    }
    /**
     * Encode a string with the charset
     *
     * <p>See the {@link http://www.faqs.org/rfcs/rfc2047.html RFC2047} for details about non-ASCII text</p>
     *
     * @author gordon@kanazawa-gu.ac.jp
     */
    function encodeIntoCharset($in_str)
    {
        $out_str = $in_str;
        if ($out_str)
        {
            // define start delimimter, end delimiter and spacer
            $end = "?=";
            $start = "=?".$this->charset."?B?";
            $spacer = $end."\r\n ".$start;

            // determine length of encoded text within chunks
            // and ensure length is even
            $length = 75 - strlen($start) - strlen($end);
//            $length = floor($length/2) * 2;
            $length = $length - ($length % 4); // fix by gardan@gmx.de

            // encode the string and split it into chunks
            // with spacers after each chunk
            $out_str = base64_encode($out_str);
            $out_str = chunk_split($out_str, $length, $spacer);

            // remove trailing spacer and
            // add start and end delimiters
            $spacer = preg_quote($spacer);
            $out_str = preg_replace("/".$spacer."$/", "", $out_str);
            $out_str = $start.$out_str.$end;
        }
       return $out_str;
    } 
    /**
     * Send the mail(s)
     *
     * <p>Since version 1.0.2 this method supports the <var>$oneByOne</var>
     * parameter</p>
     *
     * @author Sérgio Surkamp <sergio@empreendedor.com.br>
     * @since 1.0.0
     * @param int $delay Delay time
     * @param int $between Mailcount for delay
     * @param boolean $oneByOne Send one by one mail. Otherwise send all the mails with just one 'mail' call.
     */
    public function send($delay = 1, $between = 500, $oneByOne = false)
    {
        ini_set('sendmail_from', $this->from);
        if( ! is_null( $this->fromString ) )
        {
            $RFCFrom = '"'.$this->encodeIntoCharset($this->fromString).'"<'.$this->from.'>';
        }
        $cc = '';
        foreach($this->cc as $copy)
        {
            if( $cc )
            {
                $cc .= ',';
            }
            $cc .= $copy;
        }
        $bcc = '';
        foreach($this->bcc as $copy)
        {
            if( $bcc )
            {
                $bcc .= ',';
            }
            $bcc .= $copy;
        }
        $to = '';
        foreach($this->to as $copy)
        {
            if( $to )
            {
                $to .= ',';
            }
            $to .= $copy;
        }
        $message = $this->message;
        $attachHeader = '';
        $headerEnd = '';
        $mailMime = $this->contentType;
        if( ! empty( $this->file ) )
        {
            $boundary = '--='.md5(uniqid(time())).'=';
            $messageBoundary = '--='.md5(uniqid(time())).'=';
            $attachHeader = 'boundary="'.$boundary.'";';
            $headerEnd = "\n".'This is a multi-part message in MIME format.'."\n";
            $message = '--'.$boundary.'
Content-Type: '.Mail::MIME_MULTIPART_ALTERNATIVE.'; boundary="'.$messageBoundary.'"

This is a multi-part message in MIME format.

--'.$messageBoundary.'
Content-Type: '.$this->contentType.'; charset='.$this->charset.'
Content-Transfer-Encoding: 7bit

'.$this->message.'
--'.$messageBoundary.'--

';
            $mailMime = Mail::MIME_MULTIPART_MIXED;
            foreach($this->file as $info)
            {
                $message .= '--'.$boundary.'
Content-type: '.$info['mime'].';
    name="'.$this->encodeIntoCharset($info['filename']).'"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
    filename="'.$this->encodeIntoCharset($info['filename']).'"

'.chunk_split(base64_encode($info['data'])).'
';
            }
            $message .= '--'.$boundary.'--';
        }
        else
        {
            $attachHeader = 'charset="'.$this->charset.'"
Content-Transfer-Encoding: 7bit';
        }

        if($cc)
        {
            $headerEnd = 'Cc: '.$cc."\n".$headerEnd;
        }
        if($bcc)
        {
            $headerEnd = 'Bcc: '.$bcc."\n".$headerEnd;
        }
        $count = 0;
        if($oneByOne)
        {
            foreach( $this->to as $destination )
            {
            $header = 'MIME-Version: 1.0
Content-Type: '.$mailMime.'; '.$attachHeader.'
Date: '.date('r').'
From: '.$RFCFrom.'
Reply-To: '.$this->from.'
Return-Path: '.$RFCFrom.'
Subject: '.$this->encodeIntoCharset($this->subject).'
X-Priority: '.$this->priority.'
X-Mailer: PHP '.phpversion().'
'.$headerEnd.'
';
                mail( $destination, $this->encodeIntoCharset($this->subject), $message, $header );
                $count++;
                if($count == $between)
                {
                    sleep($delay);
                }
            }
        }
        else
        {
            $header = 'MIME-Version: 1.0
Content-Type: '.$mailMime.'; '.$attachHeader.'
Date: '.date('r').'
From: '.$RFCFrom.'
To: '.$to.'
Reply-To: '.$this->from.'
Return-Path: '.$RFCFrom.'
Subject: '.$this->encodeIntoCharset($this->subject).'
X-Priority: '.$this->priority.'
X-Mailer: PHP '.phpversion().'
'.$headerEnd.'
';
            mail( null, $this->encodeIntoCharset($this->subject), $message, $header );
        }
    }
}
?>


bem comentada...rsrsr

falou!

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,1k
    • Posts
      651,9k
×
×
  • Criar Novo...