<?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>eKini Web Developer Blog &#187; Zend F</title>
	<atom:link href="http://blog.ekini.net/tag/zend-f/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.ekini.net</link>
	<description>Wenbert Del Rosario: PHP, MySQL, Javascript, MVC, Zend Framework, AJAX, jQuery.</description>
	<lastBuildDate>Tue, 24 Aug 2010 00:13:42 +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>PHP: Various ways of sending email</title>
		<link>http://blog.ekini.net/2008/12/17/php-various-ways-of-sending-email/</link>
		<comments>http://blog.ekini.net/2008/12/17/php-various-ways-of-sending-email/#comments</comments>
		<pubDate>Wed, 17 Dec 2008 07:27:39 +0000</pubDate>
		<dc:creator>Wenbert</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[mail()]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Zend F]]></category>
		<category><![CDATA[zend_mail]]></category>

		<guid isPermaLink="false">http://blog.ekini.net/?p=548</guid>
		<description><![CDATA[This is quoted from the source: Most newcomers to PHP were initially attracted to the language due to its low barrier of entry. After all, adding dynamic data to a web page by using PHP (the current date, for instance) can be done with as little as one line of code. Along these lines, one [...]]]></description>
			<content:encoded><![CDATA[<p>This is quoted from the <a href="http://www.developer.com/open/article.php/3782831">source</a>:</p>
<blockquote><p>Most newcomers to PHP were initially attracted to the language due to its low barrier of entry. After all, adding dynamic data to a web page by using PHP (the current date, for instance) can be done with as little as one line of code. Along these lines, one of PHP&#8217;s common selling points is in fact its mail() function. What&#8217;s not to like about a language that can send email via a single simple function? But, the reality is there&#8217;s a bit more involved when it comes to successfully sending email in this fashion, particularly when it comes to doing so on a platform-specific basis.</p>
<p>On the Linux- and Unix-based platforms, PHP&#8217;s mail() function will send email through Sendmail, the open source mail transfer software responsible for sending as much as 75% of the world&#8217;s email. Because Sendmail is typically installed by default on Linux- and Unix-based servers, chances are the mail() function is going to work out of the box.</p>
<p>On the Windows operating system, the process is a tad more involved. Because Windows doesn&#8217;t come with a mail transfer service installed, the mail() function must instead rely on a third-party email server, as defined by PHP&#8217;s SMTP configuration directive. When mail() is called, PHP will contact this SMTP server and attempt to transmit the email using it.</p></blockquote>
<p>On the second page, the author discusses about sending mail using Zend Framework.</p>
<blockquote><p>Sending Email Using the Zend Framework</p>
<p>The first two solutions provided in this tutorial progressively solve various obstacles you&#8217;ll encounter when sending email through a PHP script. However, many unresolved tasks remain. For instance, how can you send HTML-formatted email? Include attachments? If you&#8217;re looking for the total package when it comes to sending email, capable of doing everything you could possibly conceive in this regards, look no further than the Zend Framework.</p>
<p>The Zend Framework&#8217;s Zend_Mail component, when coupled with the Zend Framework&#8217;s approach to minimizing redundancy and maximizing portability, offers the ideal solution for configuring and transmitting email through PHP-driven webpages. In this concluding section, I&#8217;ll presume you&#8217;re familiar with the Zend Framework and therefore focus upon my particular approach to using the Zend_Mail component.</p>
<p>First, within the application&#8217;s config.ini file, I define various parameters used to configure the transmission solution:</p>
<pre>; email

email.smtpserver = smtp.gmail.com
email.username   = wj@wjgilmore.com
email.password   = supersecret
email.support    = support@wjgilmore.com</pre>
<p>Within the bootstrap.php file, I configure Zend_Mail&#8217;s transport mechanism, drawing upon the parameters defined in config.ini:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$mailConfigs</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'auth'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'login'</span><span style="color: #339933;">,</span>
                     <span style="color: #0000ff;">'username'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">username</span><span style="color: #339933;">,</span>
                     <span style="color: #0000ff;">'password'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">password</span><span style="color: #339933;">,</span>
                     <span style="color: #0000ff;">'ssl'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'tls'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$tr</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Mail_Transport_Smtp<span style="color: #009900;">&#40;</span><span style="color: #000088;">$config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">smtpserver</span><span style="color: #339933;">,</span> <span style="color: #000088;">$mailConfigs</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
Zend_Mail<span style="color: #339933;">::</span><span style="color: #004000;">setDefaultTransport</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$tr</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Although this executes with each request, the overhead required to do so is minimal and will not affect performance. Finally, I invoke code similar to the following from within the appropriate controllers:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">try <span style="color: #009900;">&#123;</span>
   <span style="color: #666666; font-style: italic;">// Create a new mail object</span>
   <span style="color: #000088;">$mail</span> <span style="color: #339933;">=</span> <span style="color: #000000; font-weight: bold;">new</span> Zend_Mail<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setFrom</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">config</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">email</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from_admin</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">addTo</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;jason@example.com&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setSubject</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Your account has been created&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$email</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Thank you for registering!&quot;</span><span style="color: #339933;">;</span>
&nbsp;
   <span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">setBodyText</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$email</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
   <span style="color: #000088;">$mail</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: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">success</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">1</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span> catch <span style="color: #009900;">&#40;</span>Exception <span style="color: #000088;">$e</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">view</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">errors</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;We were unable to send your
      confirmation email. Please contact
      <span style="color: #006699; font-weight: bold;">{$this-&gt;config-&gt;email-&gt;support}</span>.&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>If you&#8217;d like to add an attachment, all you need to do is invoke the $mail object&#8217;s createAttachment() method:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">createAttachment</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;brochure.pdf&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>If you want to send HTML-formatted email, just use the setBodyHtml() method instead of setBodyText():</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$mail</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">sendBodyHTML</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">&quot;Thank &lt;b&gt;you&lt;/b&gt; for registering!&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://blog.ekini.net/2008/12/17/php-various-ways-of-sending-email/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
	</channel>
</rss>
