<?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>memeLab &#187; php</title>
	<atom:link href="http://memelab.com.au/category/php/feed/" rel="self" type="application/rss+xml" />
	<link>http://memelab.com.au</link>
	<description>Search Engine Marketing and Web Publishing Services</description>
	<lastBuildDate>Mon, 16 Apr 2012 03:12:04 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	
<xhtml:meta xmlns:xhtml="http://www.w3.org/1999/xhtml" name="robots" content="noindex" />
		<item>
		<title>Beating the mail_failed error in formmail.php</title>
		<link>http://memelab.com.au/mail_failed/</link>
		<comments>http://memelab.com.au/mail_failed/#comments</comments>
		<pubDate>Tue, 18 Nov 2008 00:31:24 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[formmail.php]]></category>
		<category><![CDATA[Web Developer Toolbar]]></category>

		<guid isPermaLink="false">http://memelab.com.au/?p=48</guid>
		<description><![CDATA[<p><p><a href="http://http://memelab.com.au/">Wordpress Customisation Melbourne</a></p><p>So, I&#8217;ve spent far too long messing with formmail.php.. but I just can&#8217;t resist getting everything just right! I was getting an obscure error, which requires a little form field validation. The problem I found during testing that if I populated form fields with the excellent Web Developer toolbar for Firefox, I would get the [...]</p></p><p><a href="http://http://memelab.com.au/">Wordpress Training Melbourne</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://http://memelab.com.au/">Wordpress Customisation Melbourne</a></p><p>So, I&#8217;ve spent far too long messing with formmail.php.. but I just can&#8217;t resist getting everything just right! I was getting an obscure error, which requires a little form field validation.</p>
<h3>The problem</h3>
<p>I found during testing that if I populated form fields with the excellent Web Developer toolbar for Firefox, I would get the following error:</p>
<blockquote><p>The following error occurred in FormMail :<br />
<strong>mail_failed</strong><br />
**********<br />
Error=Failed to send email</p></blockquote>
<p>The error whilst using the formmail tag <code>&lt;fmerroritemlist /&gt;</code> the only feedback displayed to the user was: <em></em></p>
<blockquote><p>There was an error in processing your form&#8230;</p></blockquote>
<p>Not so helpful.</p>
<p>Whilst using the error handling tags <code>&lt;fmerrorcode /&gt;</code> and <code>&lt;fmfullerror /&gt;</code>, the feedback was little better:</p>
<blockquote><p>Error Code: <strong>mail_failed</strong><br />
Failed to send email</p></blockquote>
<p>The failure was due to the email address being faulty. The Web Developer Toolbar populated the field with &#8216;email&#8217; (the name of the field), and formmail.php choked on the invalid address.</p>
<h3>The solution</h3>
<p>The solution was found in the following <a title="Tectite Forums" href="http://www.tectite.com/vbforums/showpost.php?p=3035&amp;postcount=2" target="_blank">forum post at Tectite.com</a>. We simply add a condition:</p>
<p>If an email is submitted, test it, and notify the user if it&#8217;s bad!</p>
<p>Just add the following condition to your form:</p>
<pre class="brush:xml">&lt;input type="hidden" name="conditions" value=":#
#IF#email#email ~ /^[a-z0-9_.]+@[a-z0-9_]+\.([a-z0-9_.]+)*[a-z0-9_.]$/i ##
Please enter a valid email address.#"&gt;</pre>
<p>Sorted! Now the user will be told &#8220;<em>Please enter a valid email address&#8221;</em> if, and only if, they enter something in the email field.</p>
<p>Please note that in the <a title="HTML forms with formmail.php" href="http://www.tectite.com/fmdoc/creating_forms.php" target="_blank">formmail documentation</a> the author recommends that you use either conditions, or required fields. I&#8217;ve found no problems whilst using them together in my simple scenario, but if you encounter gremlins in your error handling, <abbr title="Read The Fine Manual">RTFM</abbr>.</p>
<p><a href="http://http://memelab.com.au/">Wordpress Training Melbourne</a></p>]]></content:encoded>
			<wfw:commentRss>http://memelab.com.au/mail_failed/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Advanced Options in formmail.php</title>
		<link>http://memelab.com.au/advanced-options-in-formmail/</link>
		<comments>http://memelab.com.au/advanced-options-in-formmail/#comments</comments>
		<pubDate>Fri, 14 Nov 2008 06:00:10 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[formmail.php]]></category>
		<category><![CDATA[html email]]></category>
		<category><![CDATA[install]]></category>

		<guid isPermaLink="false">http://memelab.com.au/?p=39</guid>
		<description><![CDATA[<p><p><a href="http://http://memelab.com.au/">Wordpress Customisation Melbourne</a></p><p>I&#8217;ve spent a little more time on prettying up a recent fommail.php installation, and have come to grips with some quirks involved in getting all the juicy info possible into the email I recieve. If you are setting up formmail.php for the first time, it might be worth reading my previous post Configure formmail.php more [...]</p></p><p><a href="http://http://memelab.com.au/">Wordpress Training Melbourne</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://http://memelab.com.au/">Wordpress Customisation Melbourne</a></p><p>I&#8217;ve spent a little more time on prettying up a recent <strong>fommail.php</strong> installation, and have come to grips with some quirks involved in getting all the juicy info possible into the email I recieve.</p>
<p>If you are setting up formmail.php for the first time, it might be worth reading my previous post <a title="Installing formmail.php" href="http://memelab.com.au/configure-formmailphp-more-easily/" target="_self">Configure formmail.php more easily</a>.</p>
<p>My priorities are:</p>
<ul>
<li>using formmail.php to conceal my email address from spammers</li>
<li>setting the subject to include derived fields</li>
<li>tracking the IP address and User Agent of the user</li>
<li>compile all the data into a presentable email</li>
</ul>
<h3>Using formmail.ini</h3>
<p>My .ini file is really simple, and looks like this:</p>
<pre class="xhtml">[special_fields]
recipients = "tim@mysite.com"
;this is a comment</pre>
<p>Now I no longer need to specify recipients in my form, so the address is not harvestable, and there&#8217;s no need to use an AT_MANGLE to obsfucate the address.</p>
<p>Note that a semi-colon functions comments out a line.</p>
<p>I&#8217;ve tried including other options in formmail.ini, but few function, so I prefer to keep all the values bar recipients together in the form.</p>
<h3>Setting a useful subject line with &#8216;Derived Fields&#8217;</h3>
<p>Derived Fields allow the form to combine values that the user enters into new variables which can be used in the email or to name files.  I wanted to be able to see the User&#8217;s name in the subject line of the email (and other details.. I&#8217;ve dumbed this down for clarity), which requires defining &#8216;subject&#8217; as a derived field.</p>
<p>The <a title="Derived Fields Documentation" href="http://www.tectite.com/fmhowto/derived.php" target="_blank">documentation</a> is pretty clear about the nitty gritty of configuring derived fields, just not on including them in the html template.</p>
<p>Check the following example from my form:</p>
<pre class="xhtml">&lt;input type="hidden" name="derive_fields" value="subject=%'[Contact Form] -'%+email" /&gt;</pre>
<ul>
<li><strong>&#8216;subject=&#8217;</strong> is pretty straight-forward<strong><br />
</strong></li>
<li><strong>%&#8217;</strong>this is how to include a literal string using formmail<strong>&#8216;%</strong></li>
<li><strong>+</strong> concatenates (joins) two values with a space between.  A period joins with no space.</li>
<li><strong>email</strong> calls a field that you&#8217;ve defined somewhere else, either as a user-entered field, or defined later in the derived_fields.. stay tuned.</li>
</ul>
<p>You can define a whole lot of these values within the one hidden field.  They can get mighty confusing, so it&#8217;s best to span them over many lines, as I&#8217;ve done below:</p>
<pre class="brush:xml">&lt;input type="hidden" name="derive_fields" value="
    subject=%'[Contact Form] -'%+email,
    DateTime = %'Form was submitted: '% . %date% + %time%,
    remote_addr = REMOTE_ADDR,
    http_user_agent = HTTP_USER_AGENT" /&gt;</pre>
<p>Note the commas between each line.  You can span required fields over multiple lines in the same way.</p>
<h3>Using Derived Fields in the email template</h3>
<p>Now we have access to all those handy values we&#8217;ve defined.  Printing them in the email template is as simple as prefixing each value with a $.  Here&#8217;s a taste of my email template:</p>
<pre class="brush:xml">&lt;html&gt;
&lt;body&gt;
&lt;h1&gt;$title&lt;/h1&gt;
&lt;p&gt;$DateTime&lt;/p&gt;

&lt;pre&gt;
You can put preformat text in here,
ready to be pasted into a website,
as long as you convert all your
opening angle brackets to html entities.
Substitute each &lt; with &lt;.

&lt;/pre&gt;

&lt;ul&gt;
	&lt;li&gt;IP Address: $remote_addr&lt;/li&gt;
	&lt;li&gt;User Agent: $http_user_agent&lt;/li&gt;
&lt;/ul&gt;

&lt;/body&gt;
&lt;/html&gt;</pre>
<p>Simple, in retrospect <img src='http://memelab.com.au/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><a href="http://http://memelab.com.au/">Wordpress Training Melbourne</a></p>]]></content:encoded>
			<wfw:commentRss>http://memelab.com.au/advanced-options-in-formmail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Configure formmail.php more easily</title>
		<link>http://memelab.com.au/configure-formmail/</link>
		<comments>http://memelab.com.au/configure-formmail/#comments</comments>
		<pubDate>Tue, 11 Nov 2008 07:00:25 +0000</pubDate>
		<dc:creator>tim</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[configuration]]></category>
		<category><![CDATA[formmail.php]]></category>
		<category><![CDATA[install]]></category>

		<guid isPermaLink="false">http://memelab.com.au/?p=29</guid>
		<description><![CDATA[<p><p><a href="http://http://memelab.com.au/">Wordpress Customisation Melbourne</a></p><p>Formmail.php is a free script which delivers a user's details from a form on your site's contact page to your email inbox.  It can do file uploads, it is spam savvy, it does captcha text.. phew, it threatens to fold your washing!

The file itself is more heavily documented than any other script I've seen: comments just about outweigh the code, which ironically makes it tedious to configure manually.  Thankfully, Tectite offers a Configuration Wizard, which offers a free trial, or 7 day access for a measly US$4.95.  I highly recommend that you use it.

If, however, you find yourself configuring it repeatedly, I'd suggest making your own configuration file.  The purpose of this is to gather the 15 odd lines you actually need to edit on one page.  Why is this so useful?  Because the whole script weighs in at over 10,200 lines of code!  That's a lot of scanning through code.</p></p><p><a href="http://http://memelab.com.au/">Wordpress Training Melbourne</a></p>]]></description>
			<content:encoded><![CDATA[<p><a href="http://http://memelab.com.au/">Wordpress Customisation Melbourne</a></p><p>Formmail.php is a free script which delivers a user&#8217;s details from a form on your site&#8217;s contact page to your email inbox. It can do file uploads, it is spam savvy, it does captcha text.. phew, it threatens to fold your washing!</p>
<p>The file itself is more heavily documented than any other script I&#8217;ve seen: comments just about outweigh the code, which ironically makes it tedious to configure manually.  Thankfully, Tectite offers a Configuration Wizard, which offers a free trial, or 7 day access for a measly US$4.95.  I highly recommend that you use it.</p>
<p>If, however, you find yourself configuring it repeatedly, I&#8217;d suggest making your own configuration file.  The purpose of this is to gather the 15 odd lines you actually need to edit on one page.  Why is this so useful?  Because the whole script weighs in at over 10,200 lines of code!  That&#8217;s a lot of scanning through code.<span id="more-29"></span></p>
<h3>Configuring formmail.php</h3>
<p>First, enter your <strong>$TARGET_EMAIL</strong>, and define <strong>DEF_ALERT</strong> around line 230 in the script.  This is well <a title="formmail documentation" href="http://www.tectite.com/fmdoc/index.php" target="_blank">documented</a>.</p>
<p>The essential step is to trigger formmail&#8217;s test function, which will email you the paths that it detects on your server.    Do this by visiting the script directly in your browser:</p>
<pre>name-of-your-formmail.php?testalert=1</pre>
<p>then check your email.  This will provide you with the correct path to use when configuring further options.  I found recently, on a particularly convoluted server, that I needed the value <strong>PATH_TRANSLATED</strong>. Strip the trailing slash, and the script name off the end, so that you&#8217;re left with the a string ending in the directory containing the script:</p>
<pre>PATH_TRANSLATED: <strong>/home/www/01/mydomain.com.au/www/formmail</strong><span style="text-decoration: line-through;">/formmail.php</span></pre>
<h3>Hijacking the Configuration</h3>
<p>Enter the following line into formmail.php before the comments begin (line 3)</p>
<pre class="php">include('config.php');</pre>
<p>Now create a new file in the same directory as formmail.php, and name it, surprise.. config.php.</p>
<p>Browse through the script (the configuration is roughly between lines 230 and 520) and identify the variables that you want to set, and with each of them:</p>
<ul>
<li>copy the line to your config.php</li>
<li>comment out the original line</li>
</ul>
<p>My config file looks like so:</p>
<pre class="brush:php">&lt;?php
$TARGET_EMAIL = array(EMAIL_NAME."@mydomain\.com$");
define("DEF_ALERT","tim@mydomain.com");

$LOGDIR             = "/home/www/formmail/log";
$CSVDIR             = "/home/www/formmail/csv";
$TEMPLATEDIR        = "/home/www/formmail/templates";
$FORM_INI_FILE      = "/home/www/formmail/formmail.ini";

define("FILEUPLOADS",true);
$FILE_REPOSITORY     = "/home/www/uploads";

define("CHECK_FOR_NEW_VERSION",true);
define("CHECK_DAYS",30);

$SCRATCH_PAD         = "/home/www/formmail/scratchpad";
define("ALERT_ON_USER_ERROR",true);
?&gt;</pre>
<p>A few thoughts before signing off:</p>
<ul>
<li>I think you&#8217;d be <span style="text-decoration: line-through;">crazy</span> negligent not to use the <a title="formmail.ini documentation" href="http://www.tectite.com/fmdoc/form_ini_file.php" target="_blank">formmail.ini</a> option, which protects your email address being harvested by separating it from the html form itself</li>
<li>I recommend having <strong>ALERT_ON_USER_ERROR </strong>set to true for the first week of operation, then set it to false when you tire of receiving a stream of mail notifying that someone has forgotten to enter a required field.</li>
</ul>
<h3>Caveats</h3>
<p>This, of course, will need to be repeated if you upgrade.  In the meantime, it could save you quite a bit of frustration if you&#8217;re running backwards and forwards between your configuration, your form, and your inbox.  Tectite provides a really handy <a title="Upgrade Wizard" href="http://www.tectite.com/wizards/fmconf.php" target="_blank">Upgrade Wizard</a>, if you plan to follow the beaten path.</p>
<h3>In Conclusion</h3>
<p>I can&#8217;t help but think the formmail has been created obscure to scare people into using, and ultimately subscribing to the Configuration Wizard, but I don&#8217;t begrudge its author Russell Robinson this.  Ten thousand lines of code don&#8217;t come from nowhere!</p>
<p>Formmail is a great product, and comes at the ultimate price, and it&#8217;s saved me a number of times.</p>
<p>Formmail.php is available as a free download from <a title="Download formmail.php" href="http://www.tectite.com/formmailpage.php" target="_blank">Tectite.com</a>, and they offer a <a title="Configuration Wizard" href="http://www.tectite.com/wizards/fmconf.php" target="_blank">Configuration Wizard</a>.</p>
<p>Note: Of course, you&#8217;ll need to have PHP installed and running on your host (it&#8217;s free, and almost universal in budget setups).</p>
<p><a href="http://http://memelab.com.au/">Wordpress Training Melbourne</a></p>]]></content:encoded>
			<wfw:commentRss>http://memelab.com.au/configure-formmail/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

