<?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>Short Like A Fox &#187; mail()</title>
	<atom:link href="http://shortlikeafox.com/tag/mail/feed/" rel="self" type="application/rss+xml" />
	<link>http://shortlikeafox.com</link>
	<description>They Say I'm Short...</description>
	<lastBuildDate>Wed, 29 Jul 2009 22:21:46 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.3</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to Send Out a Mass Email Using PHP</title>
		<link>http://shortlikeafox.com/2008/09/19/how-to-send-out-a-mass-email-using-php/</link>
		<comments>http://shortlikeafox.com/2008/09/19/how-to-send-out-a-mass-email-using-php/#comments</comments>
		<pubDate>Fri, 19 Sep 2008 22:30:56 +0000</pubDate>
		<dc:creator>ShortLikeAFox</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[database]]></category>
		<category><![CDATA[mail()]]></category>

		<guid isPermaLink="false">http://shortlikeafox.com/?p=93</guid>
		<description><![CDATA[ So you want to send out a mass email or you want to create a program that can quickly be changed to send out multiple mass emails. PHP makes this easy. In this example I will assume that you have a list of email addresses you want to send a certain email to. I [...]]]></description>
			<content:encoded><![CDATA[<!-- This is a HTML comment, it will not display in any page. Feel free to remove this comment if it cause any inconvenient to you.
	Thanks for using digg digg, please visit http://www.mkyong.com/blog/digg-digg-wordpress-plugin for any comments and ideas, 
	
    Author : Yong Mook Kim
    Website : http://www.mkyong.com
	--><div style='float:right'><table> <td><iframe src='http://digg.com/api/diggthis.php?w=new&amp;u=http://shortlikeafox.com/2008/09/19/how-to-send-out-a-mass-email-using-php/&amp;t=How+to+Send+Out+a+Mass+Email+Using+PHP&amp;s=normal' height='80' width='52' frameborder='0' scrolling='no'></iframe></td></table></div><p>So you want to send out a mass email or you want to create a program that can quickly be changed to send out multiple mass emails. PHP makes this easy. In this example I will assume that you have a list of email addresses you want to send a certain email to. I will also assume that you are keeping this list in a database, but this code could easily be adjusted to use either a hardcoded email address list or list from another source.</p>
<p class="style1">&lt;?php</p>
<p class="style1">&nbsp;	</p>
<blockquote>
<p> <span class="style9">//First connect to the database that contains the email address information.</span> <br />
    $user = <span class="style1">&quot;USER&quot;</span>;<br />
    $host = <span class="style1">&quot;HOST&quot;</span>;<br />
    $password = <span class="style1">&quot;PASSWORD&quot;</span>;<br />
    $database = <span class="style1">&quot;DATABASE&quot;</span>;</p>
<p>    $cxn = <span class="style3">mysql_connect</span>($host, $user, $password) or <span class="style3">die</span> (<span class="style1">&quot;Couldn&#8217;t connect to server&quot;</span>);<br />
    <span class="style3">mysql_select_db</span>($database);</p>
<p> <span class="style9">//Query the table that contains the email addresses. Fill in your own table name here&#8230;</span> <br />
    $query = <span class="style1">&quot;SELECT * FROM theEmailAddresses &quot;</span>; <br />
    $result = <span class="style3">mysql_query</span>($query, $cxn) or <span class="style3">die</span> (<span class="style3">mysql_error</span>($cxn));<br />
    $nrows = <span class="style3">mysql_num_rows</span>($result);
  </p>
<p> <span class="style9">//Who the sender will be identified as. You can put what you want here, but it really isn&#8217;t too ethical to place an email address that you don&#8217;t control here.</span> <br />
    $from = <span class="style1">&quot;From: me@mydomain.com&quot;</span>;<br />
    <span class="style9">//A standard email subject line</span> <br />
    $subject = <span class="style1">&quot;What&#8217;s new at mydomain.com &quot;</span>;<br />
    <span class="style9">//The message</span><br />
$message = <span class="style1">&quot;Hi valued friend,</span></p>
<p><span class="style1">We now sell cookies at mydomain.com. Be sure to check it out!<br />
    Sincerely,<br />
    me&quot;</span>;</p>
<p>    <span class="style9">//We&#8217;ve already queried all of the email address. Now we just need to send the email <br />
      </span> <span class="style4">for</span> ($i <span class="style3">=</span> <span class="style1">0</span>; $i <span class="style3">&lt;</span>$nrows; $i<span class="style3">++</span>){</p>
<blockquote>
<p>$row = <span class="style3">mysql_fetch_assoc</span>($result);<br />
      <span class="style3">extract</span>($row);<br />
      <span class="style9">//Replace $email with whatever the column of email addresses is called <br />
      </span>$to = <span class="style1">&quot;$email&quot;</span>;<br />
      <span class="style9">//Send the email to each email in the database</span> <br />
    if(<span class="style3">mail</span>($to, $subject, $message, $from)){</p>
<blockquote>
<p><span class="style9">//Print the name of emails that were successfully sent. I use this just to make sure that the program hasn&#8217;t frozen. In theory their should be a steady stream of names being printed&gt;</span></p>
<p><span class="style3">echo</span>(<span class="style1">&quot;$to&lt;br/&gt;&quot;</span>); </p>
</blockquote>
<p>}</p>
</blockquote>
<p> }</p>
</blockquote>
<p><span class="style9"><br /> <br />
  </span><br />
<span class="style1">?&gt;</span></p>
<p>This bit of code takes advantage of the php <a href="http://us3.php.net/function.mail" target="_blank">mail()</a> function. This is a very powerful and easy to use function. Remember that with great power comes great responsibility. Try not to use this function for evil. </p>
]]></content:encoded>
			<wfw:commentRss>http://shortlikeafox.com/2008/09/19/how-to-send-out-a-mass-email-using-php/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
