<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	>

<channel>
	<title>Noel Rocha &#187; PHP</title>
	<atom:link href="http://www.noelrocha.com/blog/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.noelrocha.com/blog</link>
	<description>Capacitando o sistema...</description>
	<pubDate>Sun, 07 Jun 2009 22:09:50 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.7.1</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Função recursiva para evitar Sql Injection</title>
		<link>http://www.noelrocha.com/blog/2009/05/31/funcao-recursiva-para-evitar-sql-injection/</link>
		<comments>http://www.noelrocha.com/blog/2009/05/31/funcao-recursiva-para-evitar-sql-injection/#comments</comments>
		<pubDate>Sun, 31 May 2009 03:33:47 +0000</pubDate>
		<dc:creator>Noel Rocha</dc:creator>
		
		<category><![CDATA[Dicas]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programação]]></category>

		<guid isPermaLink="false">http://www.noelrocha.com/blog/?p=322</guid>
		<description><![CDATA[Sempre gostei de fazer funções recursivas e quando posso tento utilizá-las pois acho charmosas e economizam código mas elas requerem um pouco mais de raciocíonio e atenção devido a facilidade de se criar loop/laço infinito. 
A primeira função recursiva você nunca esquece. Eu lembro que a minha primeira foi uma implementação de um rm -rf [...]]]></description>
			<content:encoded><![CDATA[<p>Sempre gostei de fazer <strong>funções recursivas</strong> e quando posso tento utilizá-las pois acho charmosas e economizam código mas elas requerem um pouco mais de raciocíonio e atenção devido a facilidade de se criar loop/laço infinito. </p>
<p>A primeira função recursiva você nunca esquece. Eu lembro que a minha primeira foi uma implementação de um rm -rf em PHP.</p>
<p>A função recursiva que está logo abaixo é útil quando se tem um site vulnerável a <strong>Sql Injection</strong> por falta de crítica dos dados ou por causa da diretiva <strong><a title="Diretiva Register Globals" href="http://br.php.net/manual/pt_BR/ini.core.php#ini.register-globals" target="_blank">register_globals</a></strong> estar habilitada. Eu fiz e nunca mais precisei dar manutenção nessa função mas se precisarem é só falar.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #000000; font-weight: bold;">function</span> escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
	<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">is_array</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
		<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">get_magic_quotes_gpc</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">==</span> 1<span style="color: #009900;">&#41;</span>
			<span style="color: #000088;">$var</span> <span style="color: #339933;">=</span> <span style="color: #990000;">stripslashes</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #b1b100;">return</span> <span style="color: #990000;">mysql_escape_string</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$var</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$chave</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$valor</span><span style="color: #009900;">&#41;</span>
		<span style="color: #000088;">$var</span><span style="color: #009900;">&#91;</span><span style="color: #000088;">$chave</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$valor</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #b1b100;">return</span> <span style="color: #000088;">$var</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Seu funcionamento é muito simples.</p>
<p><em><strong>1</strong> - Receber Argumento.<br />
<strong>2</strong> - Se o argumento não for um array ele deverá ser escapado e retornado.<br />
<strong>3</strong> - Caso contrário o elemento é um array.<br />
<strong>3.1</strong> - Logo a função escape() deverá ser chamada para cada elemento do array.<br />
<strong>3.2</strong> - O resultado da chamada da função escape() deverá ser salvo na posição em que estava o elemento.<br />
<strong>3.3</strong> - O array deverá ser retornado com os seus elementos escapados.</em></p>
<p>O modo de usar essa função é muito simples e é orientado que seja chamada antes das queries que recebem valores externos.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Escapando variáveis passadas por GET</span>
<span style="color: #000088;">$_GET</span> <span style="color: #339933;">=</span> escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_GET</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">// Escapando variáveis passadas por POST</span>
<span style="color: #000088;">$_POST</span> <span style="color: #339933;">=</span> escape<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Exemplo de array escapado com essa função:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'select'</span> <span style="color: #339933;">=&gt;</span> 
  <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>
    <span style="color: #cc66cc;">0</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'car'</span><span style="color: #339933;">,</span>
    <span style="color: #cc66cc;">1</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'1 or \\\'\\\''</span><span style="color: #339933;">,</span>
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
<span style="color: #009900;">&#41;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.noelrocha.com/blog/2009/05/31/funcao-recursiva-para-evitar-sql-injection/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Indicação de sites utilizando Gmail/Google Apps na HostNet</title>
		<link>http://www.noelrocha.com/blog/2008/12/16/indicacao-de-sites-utilizando-gmailgoogle-apps-na-hostnet/</link>
		<comments>http://www.noelrocha.com/blog/2008/12/16/indicacao-de-sites-utilizando-gmailgoogle-apps-na-hostnet/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 20:28:51 +0000</pubDate>
		<dc:creator>Noel Rocha</dc:creator>
		
		<category><![CDATA[Dicas]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Programação]]></category>

		<guid isPermaLink="false">http://www.noelrocha.com/blog/?p=191</guid>
		<description><![CDATA[Esse script é baseado no post como enviar emails autenticados pelo gmail/google apps. É altamente recomendado ler tal post antes de cair de mãos na massa no post de hoje.
Vamos a algumas considerações do script:
- Assim como a HostNet o Gmail também  não permite forjar o From(&#8221;de&#8221;), ou seja, o from(&#8221;de&#8221;) sempre será o [...]]]></description>
			<content:encoded><![CDATA[<p>Esse script é baseado no post <a title="Como enviar emails autenticados pelo gmail/google apps" href="http://www.noelrocha.com/blog/2008/07/21/como-enviar-emails-autenticados-pelo-gmailgoogle-apps" target="_blank">como enviar emails autenticados pelo gmail/google apps</a>. É altamente recomendado ler tal post antes de cair de mãos na massa no post de hoje.</p>
<p>Vamos a algumas considerações do script:<br />
- Assim como a <a href="http://www.hostnet.com">HostNet</a> o Gmail também  não permite forjar o From(&#8221;de&#8221;), ou seja, o from(&#8221;de&#8221;) sempre será o email que autenticará no Gmail. Eu utilizo o reply-to no cabeçalho para o destinatário quando clicar em responder aparecer o email de quem indicou e não do email do gmail. </p>
<p>- Outra coisa, no exemplo abaixo o debug está ligado, para desligar o debug basta comentar a linha abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">      <span style="color: #0000ff;">'debug'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Debug ligado</span></pre></div></div>

<p>Esse script foi pedido pelo Ramon, acho que é isso, no post sobre o google apps.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>                                    
<span style="color: #666666; font-style: italic;">// Incluindo arquivo com a classe Mail   </span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Mail.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_METHOD'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">'POST'</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #666666; font-style: italic;">// Nome de quem está indicando o site    </span>
  <span style="color: #000088;">$indicador_nome</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'meu_nome'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>    
&nbsp;
  <span style="color: #666666; font-style: italic;">// Email de quem está indicando o site</span>
  <span style="color: #000088;">$indicador_email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'meu_email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Nome de quem receberá o email</span>
  <span style="color: #000088;">$nome</span> <span style="color: #339933;">=</span>  <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nome_do_amigo'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Email que receberá o email</span>
  <span style="color: #000088;">$to</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email_do_amigo'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Nome de quem está enviando</span>
  <span style="color: #000088;">$from</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;<span style="color: #006699; font-weight: bold;">$indicador_nome</span> &lt;<span style="color: #006699; font-weight: bold;">$indicador_email</span>&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">// Assunto da mensagem</span>
  <span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Indicação de site'</span><span style="color: #339933;">;</span>
&nbsp;
  <span style="color: #666666; font-style: italic;">/*                             
   Corpo da mensagem             
   Em caso de formulário alterar para a variável $_POST['CAMPO']
  */</span>                                                            
  <span style="color: #000088;">$body</span> <span style="color: #339933;">=</span><span style="color: #0000cc; font-style: italic;">&lt;&lt;&lt;EOM                                                 
Indicação de site de $indicador_nome!!!                         
EOM</span><span style="color: #339933;">;</span>                                                            
&nbsp;
  <span style="color: #666666; font-style: italic;">// Servidor do Gmail                                          </span>
  <span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ssl://smtp.gmail.com&quot;</span><span style="color: #339933;">;</span>                               
&nbsp;
  <span style="color: #666666; font-style: italic;">// Email do Gmail que fará o envio autenticado                </span>
  <span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'noel@noelrocha.com'</span><span style="color: #339933;">;</span>                        
&nbsp;
  <span style="color: #666666; font-style: italic;">// Sua senha do GMAIL                                         </span>
  <span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SECRETA'</span><span style="color: #339933;">;</span>                                        
&nbsp;
  <span style="color: #666666; font-style: italic;">// Cabeçalho do email                                         </span>
  <span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>                                            
    <span style="color: #0000ff;">'From'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$from</span><span style="color: #339933;">,</span>                                        
    <span style="color: #0000ff;">'Reply-to'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$from</span><span style="color: #339933;">,</span>                                        
    <span style="color: #0000ff;">'To'</span>       <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$to</span><span style="color: #339933;">,</span>                                          
    <span style="color: #0000ff;">'Subject'</span>  <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$subject</span>                                      
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                                                            
&nbsp;
  <span style="color: #000088;">$smtp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Mail</span><span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'smtp'</span><span style="color: #339933;">,</span>                                 
    <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span>                                                     
      <span style="color: #0000ff;">'host'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$host</span><span style="color: #339933;">,</span>                                      
      <span style="color: #0000ff;">'port'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">465</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// SMTPS(para mais detalhes ver /etc/services</span>
      <span style="color: #0000ff;">'auth'</span>     <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>                                             
      <span style="color: #0000ff;">'debug'</span>    <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Debug ligado                             </span>
      <span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span>                                        
      <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$password</span>                                         
    <span style="color: #009900;">&#41;</span>                                                                 
  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                                                                  
&nbsp;
  <span style="color: #666666; font-style: italic;">// Efetuando o envio autenticado                                    </span>
  <span style="color: #000088;">$mail</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$smtp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>                          
&nbsp;
  <span style="color: #666666; font-style: italic;">// Verificando se houve erro                                        </span>
  <span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>PEAR<span style="color: #339933;">::</span><span style="color: #004000;">isError</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mail</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>                                         
    <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
    <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Email enviado com sucesso!!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
  <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span>
  &lt;form method=&quot;POST&quot;&gt;
    Nome:&lt;br/&gt;
    &lt;input type=&quot;txt&quot; name=&quot;meu_nome&quot;&gt;&lt;br/&gt;
    Email:&lt;br/&gt;
    &lt;input type=&quot;txt&quot; name=&quot;meu_email&quot;&gt;&lt;br/&gt;
    Nome do seu amigo:&lt;br/&gt;
    &lt;input type=&quot;txt&quot; name=&quot;nome_do_amigo&quot;&gt;&lt;br/&gt;
    Email do amigo:&lt;br/&gt;
    &lt;input type=&quot;txt&quot; name=&quot;email_do_amigo&quot;&gt;&lt;br/&gt;
    &lt;br/&gt;
    &lt;input type=&quot;submit&quot;&gt;
  &lt;/form&gt;</pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.noelrocha.com/blog/2008/12/16/indicacao-de-sites-utilizando-gmailgoogle-apps-na-hostnet/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Hostnet estará presente no PHP Conference 2008</title>
		<link>http://www.noelrocha.com/blog/2008/11/12/hostnet-estara-presente-no-php-conference-2008/</link>
		<comments>http://www.noelrocha.com/blog/2008/11/12/hostnet-estara-presente-no-php-conference-2008/#comments</comments>
		<pubDate>Wed, 12 Nov 2008 14:12:59 +0000</pubDate>
		<dc:creator>Noel Rocha</dc:creator>
		
		<category><![CDATA[Dicas]]></category>

		<category><![CDATA[HostNet]]></category>

		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Tecnologia]]></category>

		<guid isPermaLink="false">http://www.noelrocha.com/blog/?p=151</guid>
		<description><![CDATA[A Hostnet tem o prazer de convidar a todos os seus clientes para a edição 2008 do PHP Conference, que será realizado nos dias 27, 28 e 29/11, no campus da UNIFIEO, em São Paulo. A expectativa do evento é de reunir cerca de mil participantes, entre profissionais, desenvolvedores, entusiastas PHP, estudantes e demais interessados [...]]]></description>
			<content:encoded><![CDATA[<p><img class="alignleft" style="float: left;" src="http://www.phpconf.com.br/includes/templates/padrao/imagens/logo.gif" alt="PHP Conf" width="217" height="126" />A <a href="http://www.hostnet.com.br/" target="_blank">Hostnet</a> tem o prazer de convidar a todos os seus clientes para a edição 2008 do <a href="http://www.phpconf.com.br/" target="_blank">PHP Conference</a>, que será realizado nos dias 27, 28 e 29/11, no <a href="http://www.phpconf.com.br/includes/templates/padrao/imagens/logo.gif" target="_blank">campus da UNIFIEO</a>, em São Paulo. A expectativa do evento é de reunir cerca de mil participantes, entre profissionais, desenvolvedores, entusiastas PHP, estudantes e demais interessados nesta linguagem de programação.</p>
<p>A <a href="http://www.phpconf.com.br/publico/programacao.php" target="_blank">programação</a> conta com cursos práticos, palestras técnicas, casos de sucesso, estudo de casos, painéis de discussão e com a presença de palestrantes nacionais e internacionais. Entre eles estão Christopher Jones, Luke Crouch, Todd Trichler,  Thiago Victorino, Flávio Lisboa, Pedro F. de Miranda Pinto, Tiago França Melo de Lima e outros nomes importantes do meio.</p>
<p>A <a href="http://www.hostnet.com.br/" target="_blank">Hostnet</a> é o <a href="http://br.php.net/" target="_blank">provedor de hospedagem oficial do PHP no Brasil</a> e desenvolve todas as suas ferramentas baseada nesta linguagem, como o <a href="http://www.hostnet.com.br/instalador.automatico.php" target="_blank">Instalador Automático</a>, <a href="http://www.ultramail.com.br/" target="_blank">Ultramail</a>, <a href="http://www.hostnet.com.br/demo_index.php" target="_blank">Painel de Controle</a>, <a href="http://www.hostnet.com.br/construtor.de.sites.php" target="_blank">WebFácil</a>, entre outras. Patrocinadora do evento desde sua primeira edição, o estande da <a href="http://www.hostnet.com.br/" target="_blank">Hostnet</a> estará presente, mais uma vez, e espera rever amigos e fazer novos contatos.</p>
<p>Para participar do <a href="http://www.phpconf.com.br/" target="_blank">PHP Conferece 2008</a>, acesse <a href="http://www.phpconf.com.br/publico/inscrevase.php" target="_blank">http://www.phpconf.com.br/publico/inscrevase.php.</a> As inscrições e custam entre R$ 20,00 e R$ 59,00 até o dia 21/11, tendo seu valor alterado para R$ 89,00 a partir do dia 24/11. O evento oferece caravanas, no valor de R$ 25,00 por participante.</p>
<p>Vale lembrar que as vagas são limitadas, faça já a sua <a href="http://www.phpconf.com.br/publico/inscrevase.php" target="_blank">inscrição</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.noelrocha.com/blog/2008/11/12/hostnet-estara-presente-no-php-conference-2008/feed/</wfw:commentRss>
		</item>
		<item>
		<title>Como enviar emails autenticados pelo Gmail/Google Apps</title>
		<link>http://www.noelrocha.com/blog/2008/07/21/como-enviar-emails-autenticados-pelo-gmailgoogle-apps/</link>
		<comments>http://www.noelrocha.com/blog/2008/07/21/como-enviar-emails-autenticados-pelo-gmailgoogle-apps/#comments</comments>
		<pubDate>Mon, 21 Jul 2008 15:56:30 +0000</pubDate>
		<dc:creator>Noel Rocha</dc:creator>
		
		<category><![CDATA[PHP]]></category>

		<category><![CDATA[Email]]></category>

		<category><![CDATA[Programação]]></category>

		<category><![CDATA[Scripts]]></category>

		<guid isPermaLink="false">http://www.noelrocha.com/blog/?p=11</guid>
		<description><![CDATA[Olá pessoal,
Essa semana tive que criar um script para envio de emails através do Gmail porém o servidor que estou hospedado permite apenas o envio autenticado e o Gmail aceita apenas envio autenticado.
Logo a função mail() do php não pode me ajudar em nada, pois ela não faz o envio autenticado  
Nesse momento o [...]]]></description>
			<content:encoded><![CDATA[<p>Olá pessoal,</p>
<p>Essa semana tive que criar um script para envio de emails através do Gmail porém o servidor que estou hospedado permite apenas o envio autenticado e o Gmail aceita apenas envio autenticado.</p>
<p>Logo a função mail() do php não pode me ajudar em nada, pois ela não faz o envio autenticado <img src='http://www.noelrocha.com/blog/wp-includes/images/smilies/icon_sad.gif' alt=':(' class='wp-smiley' /> </p>
<p>Nesse momento o pear salvou minha pele. Utilizando a biblioteca Pear::Mail consegui realizar esse envio.<br />
<a href="http://pear.php.net/package/Mail" target="_blank">http://pear.php.net/package/Mail</a></p>
<p>O Pear::Mail nos servidores PHP da <a href="http://www.hostnet.com.br" target="_blank">HostNet</a> já está instalado por padrão, que show =)</p>
<p>Para realizar o envio tanto autenticado bastou utilizar o script abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
<span style="color: #666666; font-style: italic;">// Incluindo arquivo com a classe Mail</span>
<span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Mail.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Destinatário da mensagem</span>
<span style="color: #000088;">$to</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;suporte@hostnet.com.br&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Assunto da mensagem</span>
<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Testando envio autenticado pelo Google Apps&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 Corpo da mensagem
 Em caso de formulário alterar para a variável $_POST['CAMPO']
*/</span>
<span style="color: #000088;">$body</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Teste efetuado com sucesso!&quot;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">// Servidor do Gmail</span>
<span style="color: #000088;">$host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;ssl://smtp.gmail.com&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Email do Gmail que fará o envio autenticado</span>
<span style="color: #000088;">$username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;noel@noelrocha.com&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Sua senha do GMAIL</span>
<span style="color: #000088;">$password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'SECRETA'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'From'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$from</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">'To'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$to</span><span style="color: #339933;">,</span>
                            <span style="color: #0000ff;">'Subject'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$subject</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$smtp</span> <span style="color: #339933;">=</span> <span style="color: #990000;">Mail</span><span style="color: #339933;">::</span><span style="color: #004000;">factory</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'smtp'</span><span style="color: #339933;">,</span>
                                <span style="color: #990000;">array</span> <span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'host'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$host</span><span style="color: #339933;">,</span>
                                          <span style="color: #0000ff;">'port'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">465</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// SMTPS(para mais detalhes ver /etc/services</span>
                                          <span style="color: #0000ff;">'auth'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span>
                                          <span style="color: #0000ff;">'debug'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">,</span> <span style="color: #666666; font-style: italic;">// Debug ligado</span>
                                          <span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$username</span><span style="color: #339933;">,</span>
                                          <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$password</span><span style="color: #009900;">&#41;</span>
                                  <span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Efetuando o envio autenticado</span>
<span style="color: #000088;">$mail</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$smtp</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">send</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #339933;">,</span> <span style="color: #000088;">$body</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// Verificando se houve erro</span>
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</span>PEAR<span style="color: #339933;">::</span><span style="color: #004000;">isError</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$mail</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Error&quot;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">getMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
  <span style="color: #b1b100;">echo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Email enviado com sucesso!!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></div></div>

<p>Caso ocorra o erro abaixo(Debug tem que estar ligado para ver):</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">DEBUG<span style="color: #339933;">:</span> Recv<span style="color: #339933;">:</span> <span style="color: #cc66cc;">535</span><span style="color: #339933;">-</span>5<span style="color: #339933;">.</span>7<span style="color: #339933;">.</span>1 Username and Password not accepted<span style="color: #339933;">.</span> Learn more at
DEBUG<span style="color: #339933;">:</span> Recv<span style="color: #339933;">:</span> <span style="color: #cc66cc;">535</span> 5<span style="color: #339933;">.</span>7<span style="color: #339933;">.</span>1 http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//mail.google.com/support/bin/answer.py?answer=14257</span>
DEBUG<span style="color: #339933;">:</span> Send<span style="color: #339933;">:</span> RSET
&nbsp;
DEBUG<span style="color: #339933;">:</span> Recv<span style="color: #339933;">:</span> <span style="color: #cc66cc;">250</span> 2<span style="color: #339933;">.</span>1<span style="color: #339933;">.</span>0 Flushed 
&nbsp;
 authentication failure <span style="color: #009900;">&#91;</span>SMTP<span style="color: #339933;">:</span> Invalid response code received from server <span style="color: #009900;">&#40;</span>code<span style="color: #339933;">:</span> <span style="color: #cc66cc;">535</span><span style="color: #339933;">,</span> response<span style="color: #339933;">:</span> 5<span style="color: #339933;">.</span>7<span style="color: #339933;">.</span>1 Username and Password not accepted<span style="color: #339933;">.</span> Learn more at
5<span style="color: #339933;">.</span>7<span style="color: #339933;">.</span>1 http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//mail.google.com/support/bin/answer.py?answer=14257)]</span>
&nbsp;
DEBUG<span style="color: #339933;">:</span> Send<span style="color: #339933;">:</span> QUIT
&nbsp;
DEBUG<span style="color: #339933;">:</span> Recv<span style="color: #339933;">:</span> <span style="color: #cc66cc;">221</span> 2<span style="color: #339933;">.</span>0<span style="color: #339933;">.</span>0 mx<span style="color: #339933;">.</span>google<span style="color: #339933;">.</span>com closing connection</pre></div></div>

<p>ou abaixo:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">p<span style="color: #339933;">&amp;</span>gt<span style="color: #339933;">;</span> authentication failure <span style="color: #009900;">&#91;</span>SMTP<span style="color: #339933;">:</span> Invalid response code received from server <span style="color: #009900;">&#40;</span>code<span style="color: #339933;">:</span> <span style="color: #cc66cc;">535</span><span style="color: #339933;">,</span> response<span style="color: #339933;">:</span> 5<span style="color: #339933;">.</span>7<span style="color: #339933;">.</span>1 Username and Password not accepted<span style="color: #339933;">.</span> Learn more at
5<span style="color: #339933;">.</span>7<span style="color: #339933;">.</span>1 http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//mail.google.com/support/bin/answer.py?answer=14257 )]</span></pre></div></div>

<p>Será necessário acessar o endereço <a href="https://www.google.com/accounts/DisplayUnlockCaptcha" target="_blank">https://www.google.com/accounts/DisplayUnlockCaptcha</a> para contas que  sejam do Gmail e https://www.google.com/a/[<strong>SEU_DOMINIO_DO_GOOGLE_APPS</strong>]/UnlockCaptcha e depois <strong>desbloquear</strong> o envio de emails sem a utilização de <strong>Captcha</strong>. Nesse endereço será necessário digitar a sua conta(sem o @ e o domínio) e a senha da mesma.</p>
<p>Caso ocorra o erro abaixo, é porque o servidor que o script está possui proteção na porta <strong>465</strong>:</p>

<div class="wp_syntax"><div class="code"><pre class="html" style="font-family:monospace;">Failed to connect to ssl://smtp.gmail.com:465 [SMTP: Failed to connect socket: Connection refused
(code: -1, response: )]</pre></div></div>

<p><strong>Obs.: <em>Esse procedimento deverá ser realizado para cada novo servidor que o script esteja rodando.</em></strong></p>
]]></content:encoded>
			<wfw:commentRss>http://www.noelrocha.com/blog/2008/07/21/como-enviar-emails-autenticados-pelo-gmailgoogle-apps/feed/</wfw:commentRss>
		</item>
	</channel>
</rss>
