<?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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Boteco Digital &#187; e-mail</title>
	<atom:link href="http://www.botecodigital.info/tag/e-mail/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.botecodigital.info</link>
	<description></description>
	<lastBuildDate>Wed, 01 Sep 2010 13:36:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Enviando email com PHPmailer</title>
		<link>http://www.botecodigital.info/php/enviando-email-com-phpmailer/</link>
		<comments>http://www.botecodigital.info/php/enviando-email-com-phpmailer/#comments</comments>
		<pubDate>Sat, 10 Jan 2009 13:02:22 +0000</pubDate>
		<dc:creator>Rodrigo Aramburu</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[classe php]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[phpmailer]]></category>

		<guid isPermaLink="false">http://192.168.0.145/wordpress/?p=30</guid>
		<description><![CDATA[O formulário de contato é uma ferramenta de comunicação de extrema importância que não pode ser tratada com desdem ao se desenvolver um site. Ela é uma das tarefas primordiais da web e devido a crescente onda de spam simplesmente deixar seu endereço de e-mail na página pode ser uma grande dor de cabeça(acreditem minha pasta spam do Gmail sabe do que fala). Veremos então como criar um pequeno formulário de contato com apenas nome, e-mail, telefone, cidade, assunto e [...]]]></description>
			<content:encoded><![CDATA[<p>O formulário de contato é uma ferramenta de comunicação de extrema importância  que não pode ser tratada com desdem ao se desenvolver um site. Ela é uma das  tarefas primordiais da <acronym title="World Wide Web">web</acronym> e devido a crescente onda de spam simplesmente  deixar seu endereço de e-mail na página pode ser uma grande dor de cabeça(acreditem  minha pasta spam do <a href="http://mail.google.com/mail/">Gmail</a> sabe do que fala).</p>
<p>Veremos então como criar um pequeno formulário de contato com apenas nome, e-mail,  telefone, cidade, assunto e mensagem. Vejamos como ficará o <acronym title="HyperText Markup Language"><acronym title="HyperText Markup Language">HTML</acronym></acronym> então:</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
</pre></td><td class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;enviar.php&quot;</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
        <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>Formulário de Contato<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">legend</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nome&quot;</span>&gt;</span>Nome<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;nome&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;40&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span>&gt;</span>E-mail:<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;email&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;40&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;telefone&quot;</span>&gt;</span>Telefone<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;telefone&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;20&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;assunto&quot;</span>&gt;</span>Assunto<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;assunto&quot;</span> <span style="color: #000066;">size</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;40&quot;</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">label</span> <span style="color: #000066;">for</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mensagem&quot;</span>&gt;</span>Mensagem<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">label</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">textarea</span> <span style="color: #000066;">cols</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;40&quot;</span> <span style="color: #000066;">rows</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;4&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;mensagem&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">textarea</span>&gt;</span>
         <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Enviar&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">fieldset</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></td></tr></table></div>

<p>Para enviar este formulário iremos utilizar uma classe <acronym title="Pre-Hypertext Processing">PHP</acronym> chamada PHPmailer(<a href="http://phpmailer.sourceforge.net/" target="_blank">http://phpmailer.sourceforge.net/</a>), então antes de começarmos é bom baixa-la e descomactar-la na pasta do script.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>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
</pre></td><td class="code"><pre class="php" style="font-family:monospace;">  <span style="color: #b1b100;">require_once</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'phpmailer/class.phpmailer.php'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #000088;">$erros</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
 <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nome'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$erros</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;O nome deve ser preenchido.&quot;</span><span style="color: #339933;">;</span>
 <span style="color: #009900;">&#125;</span>
&nbsp;
 <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
      <span style="color: #000088;">$erros</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;O E-mail deve ser preenchido.&quot;</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: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
      <span style="color: #990000;">eregi</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;([\._0-9A-Za-z-]+)@([0-9A-Za-z-]+)(\.[0-9A-Za-z\.]+)&quot;</span><span style="color: #339933;">,</span><span style="color: #000088;">$email</span><span style="color: #339933;">,</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #339933;">!</span><span style="color: #990000;">isset</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$match</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$erros</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;O e-mail informado é inválido.&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span><span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'mensagem'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
    <span style="color: #000088;">$erros</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;A mensagem deve ser preenchida.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #b1b100;">if</span><span style="color: #009900;">&#40;</span> <span style="color: #990000;">empty</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$erros</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
&nbsp;
    <span style="color: #000088;">$phpmail</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> PHPMailer<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IsSMTP</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// envia por SMTP</span>
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Host</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;mail.xxxxxx.com&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// SMTP servers</span>
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">SMTPAuth</span> <span style="color: #339933;">=</span> <span style="color: #009900; font-weight: bold;">true</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// Caso o servidor SMTP precise de autenticação</span>
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Username</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;xxxxxx@xxxxxx.com&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// SMTP username</span>
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Password</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;*********&quot;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// SMTP password</span>
&nbsp;
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">IsHTML</span><span style="color: #009900;">&#40;</span><span style="color: #009900; font-weight: bold;">true</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">From</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">FromName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nome'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">AddAddress</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;blogbotecodigital@gmail.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Subject</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$assunto</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Nome: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'nome'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;E-mail: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'email'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Telefone: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'telefone'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Assunto: &quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'assunto'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
    <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Body</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;Mensagem: &quot;</span><span style="color: #339933;">.</span><span style="color: #990000;">nl2br</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'mensagem'</span><span style="color: #009900;">&#93;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
    <span style="color: #000088;">$send</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">Send</span><span style="color: #009900;">&#40;</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;">$send</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
        <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;A Mensagem foi enviada com sucesso.&quot;</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: #0000ff;">&quot;Não foi possível enviar a mensagem. Erro: &quot;</span> <span style="color: #339933;">.</span><span style="color: #000088;">$phpmail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">ErrorInfo</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span>
&nbsp;
    <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: #000088;">$erros</span><span style="color: #339933;">;</span>
    <span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

<p>Vamos então commeçar a examinar o código. Na linha 1 apenas incluimos a classe PHPmailer no script. Na linha 5 testamos se a váriavel <span style="font-style: italic;">nome</span> enviada por POST pelo nosso formulário esta vazia, se sim acrescentamos uma mensagem na variável <span style="font-style: italic;">$erros</span>(linha 6).</p>
<p>Na linha 9 verficamos se o e-mail foi informado, se sim, na linha 13 utilizamos uma <a href="http://pt.wikipedia.org/wiki/Express%C3%B5es_regulares" target="_blank">expressão regular</a> para verficar se realmente foi informado um e-mail. Na linha 19 verficamos se foi enviado alguma mensagem.</p>
<p>Na linha 23 verficamos se não existe nenhuma mensagem de erro na variável <span style="font-style: italic;"> $erros</span>, se ela estiver vazia começa a brincadeira.</p>
<p>Instânciamos a classe <strong>PHPmailer</strong> na linha 25 para poder utiliza-la.</p>
<p>Na linha 27 definimos que utilizaremos o protocolo <a href="http://pt.wikipedia.org/wiki/Smtp" target="_blank"> <acronym title="Simple Mail Transfer Protocol"><acronym title="Simple Mail Transfer Protocol">SMTP</acronym></acronym></a>, poderiamos ter definido a opção <span style="font-style: italic;"> $phpmail-&gt;IsMail();</span> que utilizaria ao invés do <acronym title="Simple Mail Transfer Protocol"><acronym title="Simple Mail Transfer Protocol">SMTP</acronym></acronym> a função mail do <acronym title="PHP: Hypertext Preprocessor"><acronym title="Pre-Hypertext Processing">PHP</acronym></acronym>, mas utilizar a função <span style="font-style: italic;">mail()</span> não é tão recomendada pois muitos servdores de e-mail pegam como <a href="http://pt.wikipedia.org/wiki/Spam" target="_blank">spam</a>.</p>
<p>Como estamos utilizando o <acronym title="Simple Mail Transfer Protocol"><acronym title="Simple Mail Transfer Protocol">SMTP</acronym></acronym> devemos fornecer o host que enviará o email (linha 28). Na linha 29 definimos que utilizaremos autenticação para enviar o e-mail, o que também é interessante pois muitos servidores já estão utilizando este recurso para tentar diminuir o envio de spam na rede. Como definimos que iremos utilizar autenticação devemos informar o usuário e a senha, o que é feito nas linha 30 e 31.</p>
<p>Na linha 34 definimos que o e-mail será enviado em formato <acronym title="HyperText Markup Language"><acronym title="HyperText Markup Language">HTML</acronym></acronym>.</p>
<p>Nas linhas 35 e 36 definimos o e-mail e nome enviado pelo formulário como remetente da mensagem, costumo fazer isto para facilitar a resposta da mensagem.</p>
<p>Na linha 38 adicionamos o endereço do destinatário no caso nós mensmo. A classe <strong>PHPmailer</strong> também nos permite enviar uma cópia do e-mail para outro endereço <span style="font-style: italic;">$phpmail-&gt;AddCC($endereco,$nome)</span> e cópia oculta <span style="font-style: italic;"> $phpmail-&gt;AddBCC($endereco, $nome)</span>.</p>
<p>Entre as linhas 39 e 44 montamos a mensagem, sendo setado o assunto <span style="font-style: italic;">$phpmail-&gt;Subject = $assunto;</span> e montado o formulário no corpo da mensagem. Lembrando de converter as quebras de linhas <span style="font-style: italic;">\n</span> do campo mensagem para as quebra de linha em <acronym title="HyperText Markup Language"><acronym title="HyperText Markup Language">HTML</acronym></acronym>( <span style="font-style: italic;">nl2br()</span> ).</p>
<p>Na linha 46 é onde nosso e-mail é enviado(ou não?). Após esta linha apenas informamos ao usuário se a mensagem foi enviada ou não. Se não for(linha 51) mostramos o erro que ocorreu.</p>
<p>Este é apenas um pequeno exemplo do que se pode fazer com a classe <strong>PHPMailer</strong>, ela é muito mais poderosa que isto, podemos  por exemplo, enviar anexos nas mensagens.</p>
<p>Resumindo é isso, mas nunca é demais lembrar, que não importa quão bem feito seja o formulário, ele de nada valerá se não houver um funcionário bem treinado e rápido para atender o cliente.</p>
<p>Para que quiser baixar o exemplo basta clicar <a href="http://www.botecodigital.info/wp-content/donwloads/phpmailer.zip" target="_blank">aqui</a></p>
<p>Paz e prosperidade</p>
<p>[UPDATE]<br />
Pessoal, só para reforçar não se esqueçam de trocar o email de destino do nosso exemplo, estou recembendo bastante e-mail de teste no email do Boteco.<br />
[/UPDATE]</p>]]></content:encoded>
			<wfw:commentRss>http://www.botecodigital.info/php/enviando-email-com-phpmailer/feed/</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
