<?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>Radio Levhita &#187; gmail</title>
	<atom:link href="http://blog.levhita.net/tag/gmail/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.levhita.net</link>
	<description>La radio que sólo se lee pero aún así se escucha...</description>
	<lastBuildDate>Tue, 22 Jun 2010 20:19:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Send email using Gmail and PHPMailer</title>
		<link>http://blog.levhita.net/2008/03/13/send-email-using-gmail-and-phpmailer/</link>
		<comments>http://blog.levhita.net/2008/03/13/send-email-using-gmail-and-phpmailer/#comments</comments>
		<pubDate>Thu, 13 Mar 2008 16:59:20 +0000</pubDate>
		<dc:creator>Argel Arias</dc:creator>
				<category><![CDATA[PlanetaLinux]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[gmail]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[phpmailer]]></category>
		<category><![CDATA[pop]]></category>
		<category><![CDATA[smtp]]></category>

		<guid isPermaLink="false">http://blog.levhita.net/2008/03/13/send-email-using-gmail-and-phpmailer/</guid>
		<description><![CDATA[The new automatic update generator is ready, it has been a long time since OCRALight has been finished and little bit of this and that has been polished on the update generation. The process is fairly complex, it involves reverse-engineering, data-mining, packaging, distribution and a lot o fighting with our crappy Windows server that is [...]]]></description>
			<content:encoded><![CDATA[<p>The new automatic update generator is ready, it has been a long time since OCRALight has been finished and little bit of this and that has been polished on the update generation.</p>
<p>The process is fairly complex, it involves reverse-engineering, data-mining, packaging, distribution and a lot o fighting with our crappy Windows server that is between me and the final Linux liberation.</p>
<p>Every step in the road has been automatized, one by one, every problem has been solved and polished, now the final piece is in his place, the automatic email generation. Now the updates will be made and send everyday, even weekends and vacations.</p>
<p>If you are interested in the technical aspect keep reading:<br />
<span id="more-307"></span></p>
<p>How it has been done:</p>
<p>First of all, you need to have PHP with OpenSSL support, for Windows you&#8217;ll need to Install PHP and carefully select OpenSSL in the components list, if you already have PHP installed, don&#8217;t worry a re-install will keep your configuration, and you&#8217;ll be able to select OpenSSL.</p>
<p>Then download <a href="http://phpmailer.codeworxtech.com/">PHPMailer</a>,&amp;amp;nbsp; and extract it near your main php file.</p>
<p>You will need to have a Gmail account(obviously) I recommend you to make a new one just for this, mainly because the configuration need to be very precise, and you wouldn&#8217;t be able to use it freely without loosing functionality or risking to break the configuration.</p>
<p>Configure your Gmail account to use POP mail, but not IMAP, ONLY POP, just POP.</p>
<p>And now the code:</p>
<div class="blockcode" style="font-family: monospace; line-height:1.3em; width: 90%; height: 200px; border: 1px solid black; padding: 10px; white-space:nowrap; overflow:auto;"><span style="color: #000000; font-weight: bold;">&lt;?php</span><br />
<span style="color: #b1b100;">require</span><span style="color: #66cc66;">&#40;</span>”PHPMailer/<span style="color: #000000; font-weight: bold;">class</span>.phpmailer.php”<span style="color: #66cc66;">&#41;</span>;</p>
<p><span style="color: #0000ff;">$update_emails</span> = <a href="http://www.php.net/array"><span style="color: #000066;">array</span></a><span style="color: #66cc66;">&#40;</span><br />
&nbsp; &nbsp; ‘Juan Perez’ =&gt; ‘Juan_Perez@jalisco.gob.mx’,<br />
&nbsp; &nbsp; ‘Francisco Garcia’ =&gt; ‘fgarcia@hotmail.com’,<br />
&nbsp; &nbsp; ‘Diana la del Tunel’ =&gt; ‘diana@gmail.com’<br />
&nbsp; <span style="color: #66cc66;">&#41;</span>;</p>
<p><a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> “\nSending Update Email\n”;</p>
<p><span style="color: #0000ff;">$mail</span> = <span style="color: #000000; font-weight: bold;">new</span> PHPMailer<span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;&nbsp; <span style="color: #808080; font-style: italic;">// Instantiate your new class</span><br />
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">IsSMTP</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span>;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">// set mailer to use SMTP</span><br />
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">SMTPAuth</span> = <span style="color: #000000; font-weight: bold;">true</span>;&nbsp; &nbsp;<span style="color: #808080; font-style: italic;">// turn on SMTP authentication</span><br />
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">Host</span> = “smtp.gmail.com”; <span style="color: #808080; font-style: italic;">// specify main and backup server</span><br />
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">SMTPSecure</span>= ’ssl’; <span style="color: #808080; font-style: italic;">//&nbsp; Used instead of TLS when only POP mail is selected</span><br />
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">Port</span> = <span style="color: #cc66cc;">465</span>;&nbsp; &nbsp; &nbsp; &nbsp; <span style="color: #808080; font-style: italic;">//&nbsp; Used instead of 587 when only POP mail is selected</span></p>
<p><span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">Username</span> = “youremail@gmail.com”;&nbsp; <span style="color: #808080; font-style: italic;">// SMTP username, you could use your google apps address too.</span><br />
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">Password</span> = “yaourextremelynotlamepassword”; <span style="color: #808080; font-style: italic;">// SMTP password</span></p>
<p><span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">From</span> = “youremail@gmail.com”; <span style="color: #808080; font-style: italic;">//Aparently must be the same as the UserName</span><br />
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">FromName</span> = “Your name”;<br />
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">Subject</span> = ‘The subject’;<br />
<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">Body</span> = “The body of your message”;</p>
<p><span style="color: #b1b100;">foreach</span> <span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$update_emails</span> <span style="color: #b1b100;">as</span> <span style="color: #0000ff;">$name</span> =&gt; <span style="color: #0000ff;">$email</span><span style="color: #66cc66;">&#41;</span> <span style="color: #66cc66;">&#123;</span><br />
&nbsp; <span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">AddBcc</span><span style="color: #66cc66;">&#40;</span><span style="color: #0000ff;">$email</span>, <span style="color: #0000ff;">$name</span><span style="color: #66cc66;">&#41;</span>;<br />
<span style="color: #66cc66;">&#125;</span></p>
<p><span style="color: #b1b100;">if</span><span style="color: #66cc66;">&#40;</span>!<span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">Send</span><span style="color: #66cc66;">&#40;</span><span style="color: #66cc66;">&#41;</span><span style="color: #66cc66;">&#41;</span><br />
<span style="color: #66cc66;">&#123;</span><br />
&nbsp; <a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> “There was an error sending the message:” . <span style="color: #0000ff;">$mail</span>-&gt;<span style="color: #006600;">ErrorInfo</span>;<br />
&nbsp; <a href="http://www.php.net/exit"><span style="color: #000066;">exit</span></a>;<br />
<span style="color: #66cc66;">&#125;</span><br />
<a href="http://www.php.net/echo"><span style="color: #000066;">echo</span></a> “Done…\n”;<br />
<span style="color: #000000; font-weight: bold;">?&gt;</span><br />
&nbsp;</div>
<p><br style="font-family: sans-serif;" /><span style="font-family: sans-serif;">In this code I send the email to a group of people, thus I use the &#8220;Bcc:&#8221; field instead of the &#8220;To:&#8221; one, to add a &#8220;To:&#8221; you would use <span style="font-family: Courier New;">AddAddress($email, $name)</span>.</p>
<p>A possible upgrade would be to use a MySQL database to store the addresses,&amp;amp;nbsp; and provide a web interface to add and remove them. for the moment, this is enough.</p>
<p>Soo remember:</p>
<p></span></span>
<ol>
<li>PHP with OpenSSL<br />
<span style="font-family: Courier New;"><span style="font-family: sans-serif;"></span></span></li>
<li><span style="font-family: Courier New;"><span style="font-family: sans-serif;">PHPMailer</span></span></li>
<li><span style="font-family: Courier New;"><span style="font-family: sans-serif;">Create a Gmail Account<br />
</span></span></li>
<li><span style="font-family: Courier New;"><span style="font-family: sans-serif;">Activate POP</span></span></li>
<li><span style="font-family: Courier New;"><span style="font-family: sans-serif;">Host: smtp.gmail.com</span></span></li>
<li><span style="font-family: Courier New;"><span style="font-family: sans-serif;">SMTPAuth=true</span></span></li>
<li><span style="font-family: Courier New;"><span style="font-family: sans-serif;">SMTPSEcure=ssl</span></span></li>
<li><span style="font-family: Courier New;"><span style="font-family: sans-serif;">Port: 465</span></span></li>
<li><span style="font-family: Courier New;"><span style="font-family: sans-serif;">User with Domain<br />
</span></span></li>
<li><span style="font-family: Courier New;"><span style="font-family: sans-serif;">Password</span></span></li>
<li><span style="font-family: Courier New;"><span style="font-family: sans-serif;">$Mail-&amp;amp;gt;send()</span></span></li>
</ol>
]]></content:encoded>
			<wfw:commentRss>http://blog.levhita.net/2008/03/13/send-email-using-gmail-and-phpmailer/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>
