<?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>MaggsWeb:7 &#187; email</title>
	<atom:link href="http://www.maggsweb.com/tag/email/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.maggsweb.com</link>
	<description>www.maggsweb.com</description>
	<lastBuildDate>Fri, 03 Feb 2012 22:50:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Send email with attachments class</title>
		<link>http://www.maggsweb.com/php/send-email-with-attachments-class/</link>
		<comments>http://www.maggsweb.com/php/send-email-with-attachments-class/#comments</comments>
		<pubDate>Thu, 05 Aug 2010 11:01:39 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[attachment]]></category>
		<category><![CDATA[class]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[mail]]></category>

		<guid isPermaLink="false">http://www.maggsweb.com/?p=1006</guid>
		<description><![CDATA[Very similar to the previous post on the same subject, but this time put into a &#8216;class&#8217; file for neatness.. I have just used this on the new www.lady-drivers.co.uk site for sending Vouchers by email after subscribing. ?View Code PHP&#60;?php &#160; &#160; // USAGE // $mailer = new AttachMailer(&#34;emailer@maggsweb.com&#34;, &#34;you@yourdomain.com&#34;, &#34;Email Sender&#34;, &#34;hello &#60;b&#62;content&#60;/b&#62;&#34;); // [...]]]></description>
			<content:encoded><![CDATA[<p>Very similar to the previous post on the same subject, but this time put into a &#8216;class&#8217; file for neatness..<br />
I have just used this on the new <a href="http://www.lady-drivers.co.uk/Vouchers/" onclick="pageTracker._trackPageview('/outgoing/www.lady-drivers.co.uk/Vouchers/?referer=');">www.lady-drivers.co.uk</a> site for sending Vouchers by email after subscribing.</p>
<p><span id="more-1006"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p1006code2'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p10062"><td class="code" id="p1006code2"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">// USAGE</span>
<span style="color: #666666; font-style: italic;">// $mailer = new AttachMailer(&quot;emailer@maggsweb.com&quot;, &quot;you@yourdomain.com&quot;, &quot;Email Sender&quot;, &quot;hello &lt;b&gt;content&lt;/b&gt;&quot;);</span>
<span style="color: #666666; font-style: italic;">// $mailer-&gt;attachFile(&quot;a.pdf&quot;);</span>
<span style="color: #666666; font-style: italic;">// $mailer-&gt;attachFile(&quot;b.pdf&quot;);</span>
<span style="color: #666666; font-style: italic;">// $mailer-&gt;send() ? &quot;Success&quot;: &quot;Ooops, an Error occurred!&quot;;</span>
&nbsp;
&nbsp;
<span style="color: #666666; font-style: italic;">/*
 * send emails with pdf attachment
 */</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">class</span> AttachMailer<span style="color: #009900;">&#123;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$from</span><span style="color: #339933;">,</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;">$mess</span><span style="color: #339933;">,</span> <span style="color: #000088;">$hash</span><span style="color: #339933;">,</span> <span style="color: #000088;">$output</span><span style="color: #339933;">;</span>
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000088;">$documents</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/array" onclick="pageTracker._trackPageview('/outgoing/www.php.net/array?referer=');"><span style="color: #990000;">Array</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/*
	 * @params from: sender (email format)
	 * 		   to : recipient (email format)
	 * 		   subject : Subject line
	 * 		   mess : HTML formatted message
	 */</span>
	<span style="color: #000000; font-weight: bold;">function</span> __construct<span style="color: #009900;">&#40;</span><span style="color: #000088;">$_from</span><span style="color: #339933;">,</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;">$_mess</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;">from</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_from</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">to</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_to</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">subject</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_subject</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mess</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_mess</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hash</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/md5" onclick="pageTracker._trackPageview('/outgoing/www.php.net/md5?referer=');"><span style="color: #990000;">md5</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/date" onclick="pageTracker._trackPageview('/outgoing/www.php.net/date?referer=');"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'r'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/time" onclick="pageTracker._trackPageview('/outgoing/www.php.net/time?referer=');"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #666666; font-style: italic;">/*
	 * @params url : document path
	 */</span>	
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> attachFile<span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #339933;">,</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;&quot;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$attachment</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/chunk_split" onclick="pageTracker._trackPageview('/outgoing/www.php.net/chunk_split?referer=');"><span style="color: #990000;">chunk_split</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/base64_encode" onclick="pageTracker._trackPageview('/outgoing/www.php.net/base64_encode?referer=');"><span style="color: #990000;">base64_encode</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/file_get_contents" onclick="pageTracker._trackPageview('/outgoing/www.php.net/file_get_contents?referer=');"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$docName</span>    <span style="color: #339933;">=</span> <span style="color: #000088;">$name</span> <span style="color: #339933;">==</span> <span style="color: #0000ff;">&quot;&quot;</span> ? <a href="http://www.php.net/basename" onclick="pageTracker._trackPageview('/outgoing/www.php.net/basename?referer=');"><span style="color: #990000;">basename</span></a><span style="color: #009900;">&#40;</span><span style="color: #000088;">$url</span><span style="color: #009900;">&#41;</span> <span style="color: #339933;">:</span> <span style="color: #000088;">$name</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$randomHash</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hash</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$docOutput</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;--PHP-alt-<span style="color: #006699; font-weight: bold;">$randomHash</span>--<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
					 <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;--PHP-mixed-<span style="color: #006699; font-weight: bold;">$randomHash</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
					 <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Content-Type: application/pdf; name=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #006699; font-weight: bold;">$docName</span><span style="color: #000099; font-weight: bold;">\&quot;</span> <span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
					 <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Content-Transfer-Encoding: base64 <span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
					 <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Content-Disposition: attachment <span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
					 <span style="color: #339933;">.</span><span style="color: #000088;">$attachment</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">documents</span><span style="color: #009900;">&#91;</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$docOutput</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> makeMessage<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
		<span style="color: #000088;">$randomHash</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hash</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$messageOutput</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;--PHP-mixed-<span style="color: #006699; font-weight: bold;">$randomHash</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
						 <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Content-Type: multipart/alternative; boundary=PHP-alt-<span style="color: #006699; font-weight: bold;">$randomHash</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
						 <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;--PHP-alt-<span style="color: #006699; font-weight: bold;">$randomHash</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
						 <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Content-Type: text/plain; charset='iso-8859-1'<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
						 <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Content-Transfer-Encoding: 7bit<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
						 <span style="color: #339933;">.</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mess</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
						 <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;--PHP-alt-<span style="color: #006699; font-weight: bold;">$randomHash</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
						 <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Content-Type: text/html; charset='iso-8859-1'<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
						 <span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;Content-Transfer-Encoding: 7bit<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span>
						 <span style="color: #339933;">.</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">mess</span> <span style="color: #339933;">.</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
		<span style="color: #b1b100;">foreach</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">documents</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$document</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#123;</span>
			<span style="color: #000088;">$messageOutput</span> <span style="color: #339933;">.=</span> <span style="color: #000088;">$document</span><span style="color: #339933;">;</span> 
		<span style="color: #009900;">&#125;</span>
		<span style="color: #000088;">$messageOutput</span> <span style="color: #339933;">.=</span><span style="color: #0000ff;">&quot;--PHP-mixed-<span style="color: #006699; font-weight: bold;">$randomHash</span>;--&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$messageOutput</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
	<span style="color: #000000; font-weight: bold;">public</span> <span style="color: #000000; font-weight: bold;">function</span> send<span style="color: #009900;">&#40;</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;">makeMessage</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$from</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">from</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$randomHash</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">hash</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;From: <span style="color: #006699; font-weight: bold;">$from</span><span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>Reply-To: <span style="color: #006699; font-weight: bold;">$from</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>Content-Type: multipart/mixed; boundary=<span style="color: #000099; font-weight: bold;">\&quot;</span>PHP-mixed-<span style="color: #006699; font-weight: bold;">$randomHash</span><span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span>
		<span style="color: #000088;">$mail_sent</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><a href="http://www.php.net/mail" onclick="pageTracker._trackPageview('/outgoing/www.php.net/mail?referer=');"><span style="color: #990000;">mail</span></a><span style="color: #009900;">&#40;</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">to</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">subject</span><span style="color: #339933;">,</span> <span style="color: #000088;">$this</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">output</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: #b1b100;">return</span> <span style="color: #000088;">$mail_sent</span> ? <span style="color: #009900; font-weight: bold;">true</span> <span style="color: #339933;">:</span> <span style="color: #009900; font-weight: bold;">false</span><span style="color: #339933;">;</span>
	<span style="color: #009900;">&#125;</span>
&nbsp;
<span style="color: #009900;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.maggsweb.com/php/send-email-with-attachments-class/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Sending email attachments</title>
		<link>http://www.maggsweb.com/php/sending-email-attachments/</link>
		<comments>http://www.maggsweb.com/php/sending-email-attachments/#comments</comments>
		<pubDate>Sun, 24 Jan 2010 18:40:38 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[attachment]]></category>
		<category><![CDATA[email]]></category>
		<category><![CDATA[mail]]></category>

		<guid isPermaLink="false">http://www.maggsweb.com/?p=746</guid>
		<description><![CDATA[An example of how to send Text &#038; HTML email with an attachment. ?View Code PHP&#160; &#60;?php &#160; //define the receiver of the email $to = 'youraddress@example.com'; &#160; //define the subject of the email $subject = 'Test email with attachment'; &#160; //create a boundary string. It must be unique //so we use the MD5 algorithm [...]]]></description>
			<content:encoded><![CDATA[<p>An example of how to send Text &#038; HTML email with an attachment.<br />
<span id="more-746"></span></p>

<div class="wp_codebox_msgheader"><span class="right"><sup><a href="http://www.ericbess.com/ericblog/2008/03/03/wp-codebox/#examples" target="_blank" title="WP-CodeBox HowTo?" onclick="pageTracker._trackPageview('/outgoing/www.ericbess.com/ericblog/2008/03/03/wp-codebox/_examples?referer=');"><span style="color: #99cc00">?</span></a></sup></span><span class="left"><a href="javascript:;" onclick="javascript:showCodeTxt('p746code4'); return false;">View Code</a> PHP</span><div class="codebox_clear"></div></div><div class="wp_codebox"><table><tr id="p7464"><td class="code" id="p746code4"><pre class="php" style="font-family:monospace;">&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//define the receiver of the email </span>
<span style="color: #000088;">$to</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'youraddress@example.com'</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">//define the subject of the email </span>
<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'Test email with attachment'</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">//create a boundary string. It must be unique </span>
<span style="color: #666666; font-style: italic;">//so we use the MD5 algorithm to generate a random hash </span>
<span style="color: #000088;">$random_hash</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/md5" onclick="pageTracker._trackPageview('/outgoing/www.php.net/md5?referer=');"><span style="color: #990000;">md5</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/date" onclick="pageTracker._trackPageview('/outgoing/www.php.net/date?referer=');"><span style="color: #990000;">date</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'r'</span><span style="color: #339933;">,</span> <a href="http://www.php.net/time" onclick="pageTracker._trackPageview('/outgoing/www.php.net/time?referer=');"><span style="color: #990000;">time</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">//define the headers we want passed. Note that they are separated with \r\n </span>
<span style="color: #000088;">$headers</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;From: webmaster@example.com<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>Reply-To: webmaster@example.com&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">//add boundary string and mime type specification </span>
&nbsp;
<span style="color: #000088;">$headers</span> <span style="color: #339933;">.=</span> <span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\r</span><span style="color: #000099; font-weight: bold;">\n</span>Content-Type: multipart/mixed; boundary=<span style="color: #000099; font-weight: bold;">\&quot;</span>PHP-mixed-&quot;</span><span style="color: #339933;">.</span><span style="color: #000088;">$random_hash</span><span style="color: #339933;">.</span><span style="color: #0000ff;">&quot;<span style="color: #000099; font-weight: bold;">\&quot;</span>&quot;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">//read the atachment file contents into a string,</span>
<span style="color: #666666; font-style: italic;">//encode it with MIME base64,</span>
<span style="color: #666666; font-style: italic;">//and split it into smaller chunks</span>
<span style="color: #000088;">$attachment</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/chunk_split" onclick="pageTracker._trackPageview('/outgoing/www.php.net/chunk_split?referer=');"><span style="color: #990000;">chunk_split</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/base64_encode" onclick="pageTracker._trackPageview('/outgoing/www.php.net/base64_encode?referer=');"><span style="color: #990000;">base64_encode</span></a><span style="color: #009900;">&#40;</span><a href="http://www.php.net/file_get_contents" onclick="pageTracker._trackPageview('/outgoing/www.php.net/file_get_contents?referer=');"><span style="color: #990000;">file_get_contents</span></a><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'attachment.zip'</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
&nbsp;
<span style="color: #666666; font-style: italic;">//define the body of the message. </span>
&nbsp;
<a href="http://www.php.net/ob_start" onclick="pageTracker._trackPageview('/outgoing/www.php.net/ob_start?referer=');"><span style="color: #990000;">ob_start</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">//Turn on output buffering </span>
<span style="color: #000000; font-weight: bold;">?&gt;</span> 
--PHP-mixed-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$random_hash</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>  
Content-Type: multipart/alternative; boundary=&quot;PHP-alt-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$random_hash</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>&quot; 
&nbsp;
--PHP-alt-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$random_hash</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>  
Content-Type: text/plain; charset=&quot;iso-8859-1&quot; 
Content-Transfer-Encoding: 7bit
&nbsp;
Hello World!!! 
This is simple text email message. 
&nbsp;
--PHP-alt-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$random_hash</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>  
Content-Type: text/html; charset=&quot;iso-8859-1&quot; 
Content-Transfer-Encoding: 7bit
&nbsp;
&lt;h2&gt;Hello World!&lt;/h2&gt; 
&lt;p&gt;This is something with &lt;b&gt;HTML&lt;/b&gt; formatting.&lt;/p&gt; 
&nbsp;
--PHP-alt-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$random_hash</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>-- 
&nbsp;
--PHP-mixed-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$random_hash</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>  
Content-Type: application/zip; name=&quot;attachment.zip&quot;  
Content-Transfer-Encoding: base64  
Content-Disposition: attachment  
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$attachment</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span> 
--PHP-mixed-<span style="color: #000000; font-weight: bold;">&lt;?php</span> <span style="color: #b1b100;">echo</span> <span style="color: #000088;">$random_hash</span><span style="color: #339933;">;</span> <span style="color: #000000; font-weight: bold;">?&gt;</span>-- 
&nbsp;
<span style="color: #000000; font-weight: bold;">&lt;?php</span> 
<span style="color: #666666; font-style: italic;">//copy current buffer contents into $message variable and delete current output buffer </span>
<span style="color: #000088;">$message</span> <span style="color: #339933;">=</span> <a href="http://www.php.net/ob_get_clean" onclick="pageTracker._trackPageview('/outgoing/www.php.net/ob_get_clean?referer=');"><span style="color: #990000;">ob_get_clean</span></a><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> 
<span style="color: #666666; font-style: italic;">//send the email </span>
<span style="color: #000088;">$mail_sent</span> <span style="color: #339933;">=</span> <span style="color: #339933;">@</span><a href="http://www.php.net/mail" onclick="pageTracker._trackPageview('/outgoing/www.php.net/mail?referer=');"><span style="color: #990000;">mail</span></a><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: #666666; font-style: italic;">//if the message is sent successfully print &quot;Mail sent&quot;. Otherwise print &quot;Mail failed&quot; </span>
<span style="color: #b1b100;">echo</span> <span style="color: #000088;">$mail_sent</span> ? <span style="color: #0000ff;">&quot;Mail sent&quot;</span> <span style="color: #339933;">:</span> <span style="color: #0000ff;">&quot;Mail failed&quot;</span><span style="color: #339933;">;</span> 
<span style="color: #000000; font-weight: bold;">?&gt;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://www.maggsweb.com/php/sending-email-attachments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

