<?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>Web Cash &#187; e-mail</title>
	<atom:link href="http://www.earn-web-cash.com/tag/e-mail/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.earn-web-cash.com</link>
	<description>Writing, Designing, and Making Money Online</description>
	<lastBuildDate>Sun, 04 Dec 2011 22:52:34 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2</generator>
		<item>
		<title>How to Send E-Mail in PHP: A &#8220;Share This&#8221; Form</title>
		<link>http://www.earn-web-cash.com/2008/02/06/send-email-php/</link>
		<comments>http://www.earn-web-cash.com/2008/02/06/send-email-php/#comments</comments>
		<pubDate>Thu, 07 Feb 2008 01:36:52 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[Code Snippets]]></category>
		<category><![CDATA[PHP Tutorials]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[php]]></category>
		<category><![CDATA[script]]></category>
		<category><![CDATA[spam]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/02/06/send-email-php/</guid>
		<description><![CDATA[This question comes up a lot in forums &#8211; how do you send e-mail in PHP? There are plenty of reasons you&#8217;d want to do this. Perhaps you want to send a newsletter to your users. Or you want people to be able to leave feedback through e-mail. Or you just want your users to [...]]]></description>
			<content:encoded><![CDATA[<p>This question comes up a lot in forums &#8211; how do you send e-mail in PHP?</p>
<p>There are plenty of reasons you&#8217;d want to do this.  Perhaps you want to send a newsletter to your users.  Or you want people to be able to leave feedback through e-mail.  Or you just want your users to be able to e-mail the page (or a link to it) to a friend.</p>
<p>How do we do this?  The <code>mail()</code> function.<br />
<span id="more-101"></span><br />
While there are more in depth and robust ways to send e-mail with PHP, the simplest method is to use the mail() function.  In most cases this is all you need to send plain text e-mail to a number of recipients.</p>
<p>Let&#8217;s see how this function works by creating a form that lets the user &#8220;Share This Article&#8221; &#8211; e-mail a link of the current article to a friend.</p>
<h5>Examining the Mail Function</h5>
<p>First, we&#8217;ll take a look at the mail function.  It&#8217;s pretty simple.</p>
<p><code>bool mail($to, $subject, $content, $headers)</code></p>
<p>mail() returns a boolean value &#8211; true for success, false for failure.</p>
<p>The first three parameters are pretty simple.  $to is the sending e-mail address (your user).  $subject is the subject line of your message (one line &#8211; no linebreaks!).  $content is a string containing the text of the message.</p>
<p>$headers is optional.  It can be used to add additional headers &#8211; such as cc: or bcc: lines.  You can also use the $headers to add a &#8220;From:&#8221; &#8211; otherwise the standard sending e-mail addressing in the php.ini file is used.</p>
<h5>Building the Form</h5>
<p>Before we get to the script processing, let&#8217;s build a quick HTML form to get some user input.</p>
<p>The form should give us the sender&#8217;s e-mail address and name along with the recipient&#8217;s e-mail address and name.  For now, we&#8217;ll hard-code the subject and message, although this could be gathered in the form as well.</p>

<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">form</span> <span style="color: #000066;">method</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;post&quot;</span> <span style="color: #000066;">action</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;share.php&quot;</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sendname&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sendname&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sendaddress&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;sendaddress&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recname&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recname&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text&quot;</span> <span style="color: #000066;">name</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recaddress&quot;</span> <span style="color: #000066;">id</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;recaddress&quot;</span> <span style="color: #66cc66;">/</span>&gt;&lt;<span style="color: #000000; font-weight: bold;">br</span> <span style="color: #66cc66;">/</span>&gt;</span>
  <span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">input</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;submit&quot;</span> <span style="color: #000066;">value</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;Send Message&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">form</span>&gt;</span></pre></div></div>

<p>That should gather the four pieces of input for us.</p>
<h5>Processing the Input and Sending the Message</h5>
<p>Now we can add build a quick php snippet to process the form input, send it to the mail() function, and let the user know if the mail was sent or not.  For the sake of brevity, I won&#8217;t include a lot of error checking and validation &#8211; but you should if you&#8217;re implementing this for real.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000088;">$sendName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sendname'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$sendAddress</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'sendaddress'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$recName</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'recname'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$recAddress</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$_POST</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'recaddress'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Get the URL of the page we're on</span>
<span style="color: #000088;">$pageURL</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">'http://'</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'SERVER_NAME'</span><span style="color: #009900;">&#93;</span> <span style="color: #339933;">.</span> <span style="color: #000088;">$_SERVER</span><span style="color: #009900;">&#91;</span><span style="color: #0000ff;">'REQUEST_URI'</span><span style="color: #009900;">&#93;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">//  Build the message</span>
<span style="color: #000088;">$content</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Hey <span style="color: #006699; font-weight: bold;">$recName</span>,
&nbsp;
I found this &lt;a href='<span style="color: #006699; font-weight: bold;">$pageURL</span>'&gt;cool article&lt;/a&gt; on Web Cash.  Why don't you read it and tell me what you think.
&nbsp;
Later,
- <span style="color: #006699; font-weight: bold;">$sendName</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #000088;">$to</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$recAddress</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$subject</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">&quot;Cool Article on Web Cash - Check It Out!&quot;</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;">$sendAddress</span>&quot;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #b1b100;">if</span> <span style="color: #009900;">&#40;</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;">$content</span><span style="color: #339933;">,</span> <span style="color: #000088;">$headers</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;Mail was sent successfully!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span>  <span style="color: #b1b100;">else</span> <span style="color: #009900;">&#123;</span>
   <span style="color: #b1b100;">echo</span> <span style="color: #0000ff;">&quot;There was an error.  Doh!&quot;</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

<p>And that&#8217;s about all there is to it&#8230;</p>
<h5>Jazzing It Up</h5>
<p>Once you understand how the mail() function works, you can improve the form a lot.</p>
<p>You could allow the user to input their own message, using a textarea.  You could also allow them to enter a custom subject in a text field.</p>
<p>You could allow multiple recipients with extra text fields.  To do this, separate each e-mail address with a , and a space &#8211; like &#8220;joe@bob.com, bob@joe.com&#8221; &#8211; in the $to variable.</p>
<p>A few words of caution, though.</p>
<p>First, you&#8217;ll often run into trouble using the mail() function on a local server.  If you do, I&#8217;d suggest testing your script on a remote server before you pull your hair out for no reason.</p>
<p>Second, beware of spam.  This is a good exercise to go through to understand the mail() function, but you should be aware that people do use forms to spam people.  You may want to find a captcha module and use that to verify your users are real people &#8211; or you could inadvertently be spamming the world with email about your articles.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/02/06/send-email-php/feed/</wfw:commentRss>
		<slash:comments>20</slash:comments>
		</item>
		<item>
		<title>Why Don&#8217;t My Images Appear in My HTML E-mail?</title>
		<link>http://www.earn-web-cash.com/2008/01/16/why-dont-my-images-appear-in-my-html-e-mail/</link>
		<comments>http://www.earn-web-cash.com/2008/01/16/why-dont-my-images-appear-in-my-html-e-mail/#comments</comments>
		<pubDate>Wed, 16 Jan 2008 22:33:55 +0000</pubDate>
		<dc:creator>Walkere</dc:creator>
				<category><![CDATA[HTML Tutorials]]></category>
		<category><![CDATA[Redirected]]></category>
		<category><![CDATA[Web Design]]></category>
		<category><![CDATA[e-mail]]></category>
		<category><![CDATA[html]]></category>
		<category><![CDATA[image]]></category>
		<category><![CDATA[link]]></category>

		<guid isPermaLink="false">http://www.earn-web-cash.com/2008/01/16/why-dont-my-images-appear-in-my-html-e-mail/</guid>
		<description><![CDATA[I was browsing around the PHP forum on Daniweb and came across this problem in a post. Here&#8217;s the situation. The guy wanted to send out a newsletter, so he grabbed a pre-fabbed newsletter script. The PHP script seemed to work fine &#8211; it read an HTML template and then fired off the e-mail in [...]]]></description>
			<content:encoded><![CDATA[<p>I was browsing around the PHP forum on Daniweb and came across <a href="http://www.daniweb.com/forums/thread104769.html">this problem in a post</a>.</p>
<p>Here&#8217;s the situation.</p>
<p>The guy wanted to send out a newsletter, so he grabbed a pre-fabbed newsletter script.  The PHP script seemed to work fine &#8211; it read an HTML template and then fired off the e-mail in HTML form.</p>
<p>There was just one problem: none of the images were appearing in the HTML e-mail when he tried to view it.<br />
<span id="more-41"></span><br />
What was the culprit?  The PHP script?  Or simply some faulty HTML?</p>
<p>It turns out the PHP script was working just as intended.  If you view his post, you can get a copy of the source code.  I haven&#8217;t tested it, but he claims it worked fine.</p>
<p>The problem was a simple mistake in HTML coding.</p>
<p>When the img tags were declared, the src attribute was set with a <strong>relative url</strong>  instead of an <strong>absolute url</strong>.</p>
<p>What&#8217;s the difference?</p>
<p>A <strong>relative url</strong> tells the browser the path to a file from the current file&#8217;s directory location.  So, for example, let&#8217;s say I have a file &#8220;index.html&#8221; and a file &#8220;guide.html&#8221; inside the directory &#8220;web-design-guides&#8221; on the domain &#8220;http://www.earn-web-cash.com.&#8221;</p>
<p>If I want to create a link from &#8220;index.html&#8221; to &#8220;guide.html&#8221; using a relative url, I simply use this tag&#8230;</p>
<p><code>
<pre>&lt;a href="guide.html"&gt;Guide.html&lt;/a&gt;</pre>
<p></code></p>
<p>That tells the browser to look inside the same directory for the file &#8220;guide.html.&#8221;</p>
<p>A <strong>absolute url</strong> defines the absolute path to a file.  In the same example, we&#8217;d have to include in the href the domain, the directory, and the file name, like so&#8230;</p>
<p><code>
<pre>&lt;a href="http://www.earn-web-cash.com/
  web-design-guides/guide.html"&gt;Guide.html&lt;/a&gt;</pre>
<p></code></p>
<p>The advantage of relative URLs is that they&#8217;re quick to type and they make webpages easily portable.  If all of my links are relative and I move the entire site to a new server, I don&#8217;t have to edit anything.</p>
<p>If I had used absolute urls, I would have had to change the domain name in every anchor tag.  The advantage of absolute urls, though, is that they can be accessed no matter where the page is accessed.</p>
<p>So, for example, if I turn the webpage into an e-mail (or if it&#8217;s read in an rss reader), the absolute url is still valid.  If I use a relative url in an html e-mail, the reader&#8217;s browser won&#8217;t be able to find the file &#8211; it will look in the directory that the e-mail script is running to find the file you&#8217;re linking to.</p>
<p>So what&#8217;s the lesson here?</p>
<p>If you&#8217;re writing HTML that is going to be displayed somewhere <strong>other</strong> than your server &#8211; i.e. in an e-mail, cached on someone&#8217;s hard drive, or on an rss reader &#8211; remember to always use absolute urls.</p>
<p>This is especially important for <code>&lt;img&gt;</code> tags &#8211; because they are almost always declared in regular pages as relative urls.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.earn-web-cash.com/2008/01/16/why-dont-my-images-appear-in-my-html-e-mail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

