1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
|
<?php @set_time_limit(0);
ini_set ( 'max_execution_time', '0' ); @ini_set('session.gc_maxlifetime', '3600');
require_once("../_private/conectar.php");
include("../mail/class.phpmailer.php"); //include("../mail/class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$id = $_REQUEST["id_news"]; $quant = 5; //número de mensagens enviadas de cada vez $y = $_REQUEST["ct"];;
$sec = 20; //tempo entre o envio de um pacote e outro (em segundos) ?> <?php $ok = 0; $inicio = 0; $fim = $inicio + $quant;
$sql = mysql_query("SELECT idcadastro_news, email, news FROM cadastro_news where ativo='s' and (news <> '$id' or news is NULL or enviado = 0) order by idcadastro_news desc limit $inicio,$fim") or die ("Erro ao selecionar usuarios - Cod(1)");
$registros = mysql_num_rows($sql);
if($registros==0) { echo '<table width="500"><tr><td class="alerta">Todas as mensagens foram enviadas!</td></tr></table>'; $ok = 1; }
$mat = mysql_query("SELECT * from news where idnews='$id'") or die ("Erro ao selecionar"); $total = mysql_num_rows($mat);
if ($total > 0 ){ $cont =1; $linha = mysql_fetch_array($mat); $idnews = base64_encode($linha['idnews']); $imagem = $linha['promocao']; $texto1 = $linha['texto']; $assunto = $linha['titulo']; $not1 = $linha['noticia1']; $not2 = $linha['noticia2']; $not3 = $linha['noticia3']; mysql_free_result($mat); $nots=""; if (($not1<>'') and ($not1<>NULL)){ $sel_n = mysql_query("SELECT idartigo,titulo,intro, imagem FROM artigo where idartigo='".$not1."' limit 0,1") or die ("Erro ao selecionar usuarios - Cod(1)"); $tot_n = mysql_num_rows($sel_n); if ($tot_n){ $i_n1 = mysql_result($sel_n,0,3); if ($i_n1<>''){ $in1 = "<td style='width:180px'><a href='http://www.sivana.com.br/noticia/$not1' border='0'><img src='http://www.sivana.com.br/userfiles/image/".$i_n1."' width='180'></a></td>"; }else{ $in1 =""; } $titulo1=mysql_result($sel_n,0,1); $chamada1=mysql_result($sel_n,0,2); $nots.="<tr><td style='border-bottom:1px solid #E9E9E9'> <table border='0' cellspacing='2'> <tr> $in1 <td><font face='Arial, Helvetica, sans-serif' size='3' color='#155391'><a href='http://www.sivana.com.br/noticia/$not1'>$titulo1</a></font><br><font face='Arial, Helvetica, sans-serif' size='2' color='#333333'>$chamada1</font> </td> </table> </td></tr>"; } }
if (($not2<>'') and ($not2<>NULL)){ $sel_n = mysql_query("SELECT idartigo,titulo,intro, imagem FROM artigo where idartigo='".$not2."' limit 0,1") or die ("Erro ao selecionar usuarios - Cod(1)"); $tot_n = mysql_num_rows($sel_n); if ($tot_n){ $i_n2 = mysql_result($sel_n,0,3); if ($i_n2<>''){ $in2 = "<td style='width:180px'><a href='http://www.sivana.com.br/noticia/$not2' border='0'><img src='http://www.sivana.com.br/userfiles/image/".$i_n2."' width='180'></a></td>"; }else{ $in2 =""; } $titulo2=mysql_result($sel_n,0,1); $chamada2=mysql_result($sel_n,0,2); $nots.="<tr><td style='border-bottom:1px solid #E9E9E9'> <table border='0' cellspacing='2'> <tr> $in2 <td><font face='Arial, Helvetica, sans-serif' size='3' color='#155391'><a href='http://www.sivana.com.br/noticia/$not2' >$titulo2</a></font> </td> </table> </td></tr>"; } } if (($not3<>'') and ($not3<>NULL)){ $sel_n = mysql_query("SELECT idartigo,titulo,intro, imagem FROM artigo where idartigo='".$not3."' limit 0,1") or die ("Erro ao selecionar usuarios - Cod(1)"); $tot_n = mysql_num_rows($sel_n); if ($tot_n){ $i_n3 = mysql_result($sel_n,0,3); if ($i_n3<>''){ $in3 = "<td style='width:180px'><a href='http://www.sivana.com.br/noticia/$not3' border='0'><img src='http://www.sivana.com.br/userfiles/image/".$i_n3."' width='180'></a></td>"; }else{ $in3 =""; } $titulo3=mysql_result($sel_n,0,1); $chamada3=mysql_result($sel_n,0,2); $nots.="<tr><td style='border-bottom:1px solid #E9E9E9'> <table border='0' cellspacing='2'> <tr> $in3 <td><font face='Arial, Helvetica, sans-serif' size='3' color='#155391'><a href='http://www.sivana.com.br/noticia/$not3' >$titulo3</a></font> </td> </table> </td></tr>"; } }
$contador = 0; while ($dados = mysql_fetch_array($sql)){ $mail = new PHPMailer();
//$body = $mail->getFile('contents.html'); //$body = eregi_replace("[\]",'',$body); $mail->IsSMTP(); $mail->SMTPDebug = 1; $mail->SMTPAuth = true; // enable SMTP authentication // $mail->SMTPSecure = "ssl"; // sets the prefix to the servier $mail->Host = "smtp.sivana.com.br"; $mail->Port = 587; $mail->Username = "webmaster@sivana.com.br"; $mail->Password = "09sivana"; $mail->From = "webmaster@sivana.com.br"; $mail->FromName = "Sivana"; $mail->Subject = $assunto;
$mail->IsHTML(true); // send as HTML if ($imagem <> ""){ $imagem2 ='http://www.sivana.com.br/images/logo_sivana2.jpg'; $i_anexo ="<tr> <td colspan='2' align='center'><img src='http://www.sivana.com.br/news/$imagem'></td> </tr>"; }else{ $imagem2 ='http://www.sivana.com.br/images/logo_sivana.jpg'; $i_anexo = ""; } $cli = base64_encode($dados['idcadastro_news']);
//Agora basta imprimir na tela... $body = " <html> <head> <meta http-equiv='Content-Type' content='text/html; charset=iso-8859-1' /> </head> <body link='#155391' vlink='#333333' alink='#333333' style='background-color:#fff; margin:0px; padding:0px' spellcheck='false'> <table cellspacing='0' cellpadding='0' border='0' width='545' bgcolor='#F1F1F1'> <tr> <td style='padding:20px'> <div style='text-align:center;margin:10px'><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #666;'>Caso não esteja visualizando este e-mail, por favor acesse <A title='http://www.sivana.com.br/news/' href='http://www.sivana.com.br/news.php?op=".$id."'>aqui</A></span></div> <table width='100%' border='0' cellspacing='6' cellpadding='0' bgcolor='#FFFFFF'> <tr> <td colspan='2' align='center' bgcolor='#FFFFFF'><a href='http://www.sivana.com.br'><img src=$imagem2></a></td> </tr> $i_anexo $nots <tr><td bgcolor='#FFFFFF'><font face='Arial, Helvetica, sans-serif' size='2' color='#333333'>$texto1</font></td></tr> <tr> <td></td> </tr> </table> <table bgcolor='#165491' border='0' cellspacing='5' cellpadding='5' width='100%' > <tr> <td> <font color='#FFFFFF' face='Arial, Helvetica, sans-serif'><strong><font size='2'>SIVANA </font></strong><font size='2'> - <a href='http://www.sivana.com.br' style='color:#FFFFFF'>www.sivana.com.br</a></font></font> </td> </tr> </table> <table bgcolor='#FFFFFF' border='0' cellspacing='5' cellpadding='5' width='100%' > <tr><td> <table width='225' border='0' cellspacing='0' cellpadding='0' align='right'> <tr> <td><span style='font-family: Arial, Helvetica, sans-serif; font-size: 11px; color: #155391;'>Siga nos nas redes sociais:</span></td> <td><table width='70' border='0' cellspacing='0' cellpadding='0'> <tr> <td width='35'><a href='https://www.facebook.com/sivana.sivana.543?ref=ts&fref=ts'><img src='http://www.sivana.com.br/images/icon-face.jpg' width='34' height='33' border='0'></a></td> </tr> </table></td> </tr> </table> </td></tr></table> <br> <p style='font-family: Arial, Helvetica, sans-serif; color: #666; font-size: 12px;'>O SIVANA respeita a sua privacidade. Você optou por receber este e-mail, por isso esperamos que tenha apreciado nossas novidades. Caso não queira mais receber nossos e-mails <a href='http://www.sivana.com.br/sair_lista.php?cli=".$cli."&op=1'>clique aqui </A>e altere seu cadastro.<br> Não responda este e-mail, qualquer dúvida entre em <a href='http://www.sivana.com.br/contato'> <STRONG>Contato</STRONG></a><BR> </p> </td></tr></table> </body> </html> "; //HTML Body //$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test //$mail->WordWrap = 50; // set word wrap $mail->MsgHTML($body); $mail->AddAddress($dados['email']);
$dia = date("Y-m-d H:i:s"); $id_e = $dados['idcadastro_news'];
if(!$mail->Send()) { echo "<table class=erro><tr align=center><td>Ocorreu um erro durante o envio do email.</td></tr></table>".$mail->ErrorInfo; $sql2 = mysql_query("update cadastro_news set news='$id', enviado ='0', dia='$dia', erro = '".$mail->ErrorInfo."' where idcadastro_news='$id_e'") or die ("Erro ao selecionar usuarios - Cod(2)"); $sql3 =mysql_query("insert into relatorio2 values ('','$id_e','$id','$dia','erro: ".$mail->ErrorInfo."')") or die ("Erro ao selecionar usuarios - Cod(3)"); }else{ $sql2 = mysql_query("update cadastro_news set news='$id', enviado ='1', dia='$dia',erro='' where idcadastro_news='$id_e'") or die ("Erro ao selecionar usuarios - Cod(3)"); $sql3 =mysql_query("insert into relatorio2 values ('','$id_e','$id','$dia','sucesso')") or die ("Erro ao selecionar usuarios - Cod(4)"); } $contador++;
}// if while
} $x = $y + $contador; echo 'News - '.$id; echo '<br>Mensagem - '.$x;
if ($registros != 0){ echo '<br>Aguarde Enviando...'; }else{ echo "<br><a href=index_news.php>Voltar</a>"; echo "<br><a href=relatorio2.php?id_news=".$id."&lista=".$lista.">Exibir Relatório</a>"; }
if ($contador == $quant){ echo '<META HTTP-EQUIV="Refresh" CONTENT="30; url=enviar_news_rep.php?id_news='.$id.'&ct='.$x.'">'; } if(!$ok){ echo '<META HTTP-EQUIV="Refresh" CONTENT="60; url=enviar_news_rep.php?id_news='.$id.'&ct='.$x.'">'; }
?>
|