<?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>A K Chauhan's Blog &#187; Email</title>
	<atom:link href="http://www.akchauhan.com/tag/email/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.akchauhan.com</link>
	<description>PHP, MySql, JavaScript, JQuery, Prototype, Drupal, HTML, CSS and more...</description>
	<lastBuildDate>Mon, 02 Jan 2012 03:29:10 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How know recipient read the email or newsletter?</title>
		<link>http://www.akchauhan.com/how-know-recipient-read-the-email-or-newsletter/</link>
		<comments>http://www.akchauhan.com/how-know-recipient-read-the-email-or-newsletter/#comments</comments>
		<pubDate>Wed, 22 Apr 2009 04:55:32 +0000</pubDate>
		<dc:creator>anil</dc:creator>
				<category><![CDATA[HTML]]></category>
		<category><![CDATA[PHP]]></category>
		<category><![CDATA[Email]]></category>
		<category><![CDATA[GD Library]]></category>

		<guid isPermaLink="false">http://www.akchauhan.com/?p=254</guid>
		<description><![CDATA[Sometimes we send the newsletters or emails to lot of peoples and we want to know how many of them read it. Normally the websites like Gmail, Yahoo, Hotmail don&#8217;t provide any facility for this purpose. But we can know that by sending HTML emails. HTML Emails &#8211; HTML emails are emails which can contain [...]]]></description>
			<content:encoded><![CDATA[<p>Sometimes we send the newsletters or emails to lot of peoples and we want to know how many of them read it. Normally the websites like Gmail, Yahoo, Hotmail don&#8217;t provide any facility for this purpose. But we can know that by sending HTML emails. <br/><br/> <strong>HTML Emails</strong> &#8211; HTML emails are emails which can contain HTML tags in email body. Like &lt;table&gt;, &lt;tr&gt;, &lt;td&gt;, etc.<br/><br/> The main thing here is we need to send some information to our server when user open the email. So for this, we can place an image in email body and when user open this email the browser send request to our webserver for this image. We can also achieve this by adding <strong>javascript code</strong> or hidden <strong>iframe</strong> but normally email clients don&#8217;t support javascript code and iframes in email body and they strips out this unwanted code form email body. So, the best way to achieve this is by using images.<br/><br/></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;">/*send_newsletter.php*/</span>
&nbsp;
<span style="color: #000088;">$newsletterid</span> <span style="color: #339933;">=</span> <span style="color: #cc66cc;">25</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// array of recipients</span>
<span style="color: #000088;">$recipients</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'test1@yahoo.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test2@yahoo.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test3@yahoo.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test4@gmail.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test5@gmail.com'</span><span style="color: #339933;">,</span> 
	<span style="color: #0000ff;">'test6@hotmail.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test7@hotmail.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test8@aol.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test9@aol.com'</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'test10@yahoo.com'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// subject</span>
<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Newsletter for April'</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// message</span>
<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;
&lt;html&gt;
&lt;head&gt;
  &lt;title&gt;Newsletter for April&lt;/title&gt;
&lt;/head&gt;
&lt;body&gt;
  &lt;p&gt;This is a Demo Newsletter. This is a Demo Newsletter. This is a Demo Newsletter. This is a Demo Newsletter. 
  This is a Demo Newsletter. This is a Demo Newsletter. This is a Demo Newsletter. This is a Demo Newsletter. 
  This is a Demo Newsletter. This is a Demo Newsletter. This is a Demo Newsletter. This is a Demo Newsletter. &lt;/p&gt;
  &lt;img src='http://www.akchauhan.com/newsletter_read.php?newsletterid=<span style="color: #006699; font-weight: bold;">{$newsletterid}</span>' height='1' width='1' /&gt;&lt;br/&gt;&lt;br/&gt;
  Thanks,&lt;br/&gt;
  www.akchauhan.com
&lt;/body&gt;
&lt;/html&gt;&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// To send HTML mail, the Content-type header must be set</span>
<span style="color: #000088;">$headers</span>  <span style="color: #339933;">=</span> <span style="color: #0000ff;">'MIME-Version: 1.0'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;rn&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'Content-type: text/html; charset=iso-8859-1'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;rn&quot;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">'From: AKChauhan Blog &lt;anil@akchauhan.com&gt;'</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;rn&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$recipients</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$to</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
	<span style="color: #666666; font-style: italic;">// Mail it</span>
	<span style="color: #990000;">mail</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$message</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</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><br/></p>
<p>I have used a variable <strong>$newsletterid</strong> to track newsletter. We can also send some extra information in query string as per our requirement.<br/> Like</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;">http<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">//www.akchauhan.com/newsletter_read.php?newsletterid=$newsletterid&amp;userid=$userid</span></pre></div></div>

<p><br/></p>
<p><strong>Note:</strong> Here I have used <strong>mail()</strong> function only to make demonstration simple. mail() function is not suitable for sending large number of email in loop. Better we use <strong>PEAR::Mail</strong> or <strong>PEAR::Mail_Queue</strong> packages for sending large number of email.<br/><br/></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;">/*newsletter_read.php*/</span>
&nbsp;
<span style="color: #000088;">$newsletterid</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_GET</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'newsletterid'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #666666; font-style: italic;">/*Write some code to update your read counter in your database. Or, do whatever you want to 
do when user open your newsletter.*/</span>
<span style="color: #990000;">mysql_query</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'UPDATE info SET newsletter_count = newsletter_count + 1 WHERE newsletterid = '</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$newsletterid</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// We'll be outputting a JPEG</span>
<span style="color: #990000;">header</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'Content-Type: image/jpeg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$im</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><span style="color: #990000;">imagecreatefromjpeg</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'images/one_pixel_small_white_image.jpg'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #990000;">imagejpeg</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #990000;">imagedestroy</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$img</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><br/></p>
<p>In above code, first we updated our newsletter read counter in database. We can do other things also like send an email to admin etc. as per requirement. Then we set the <strong>Content-Type</strong> to <strong>image/jpeg</strong> as we are going to send a jpeg image. So, we need to tell the browser about the content type of our response. Then, we created a 1 pixel white image usng GD library and outputted it to browser using <strong>imagejpeg()</strong> function.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.akchauhan.com/how-know-recipient-read-the-email-or-newsletter/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

