- Home »
- Page with a long title »
- Subpage with also a long title »
- Subsubpage with again a long title »
- Current location
Test mail during PHP development without a mailserver
During development I usually don’t want to send out email to recipients. I just want to make sure it will get sent, but I don’t care about it reaching it’s destiny (yet). Basically testing that my code does indeed send out mails when I ask it to do so ![]()
After searching for some time I’ve found a brilliant little one-liner written by Sean Coates some time ago. It’s a quick and dirty hack, but it works brilliantly for my purposes.
I’ve elaborated a bit more on Sean’s piece mainly on the installation, so even if you’re not that experienced you should be able to follow along. Also read Sean’s article as it contains a more sophisticated solution as well!
Preamble
I use Linux on my development machines, but I suppose it should work with any Unixish type of OS, such as OS X or *BSD. Probably doesn’t work on Windows (leave a comment for a Windows based solution).
- Ok, first put the following line in a file called ‘logmail’ (without the quotes!):
cat >> /tmp/test-emails-sent.log - Save the file somewhere you can find it back
In my case, like Sean, I’ve used /usr/local/binas the directory for this file. - Then make sure it has execute rights. You may set it by typing in:
chmod +x /usr/local/bin/logmail - Finally if you use PHP you need to change the sendmail_path variable in your php.ini. In my case (I’m using Ubuntu 11.04 and 11.10) I’ve added a file called mail.ini to the
/etc/php5/conf.ddirectory with the following line:
sendmail_path=/usr/local/bin/logmail - Restart Apache by typing
sudo service apache2 restart - Test your application’s mail sending capabilities by looking at the test-emails-sent.log in your /tmp directory
Keep track of configuration settings during development with multiple developers and WordPress Multisite
In this post I’ve written down my methods to make deployment and changing locations of WordPress Multisite installations easier by adhering to certain assumptions
Deploying WordPress from a local machine to another location such as a testserver is annoying, because there is no easy way to export and import settings (although menu’s and other content can be exported and imported!). WordPress saves configuration options in the database and often these settings are part of serialized arrays (see Serialization) . Making it hard to change these by hand or using a deployment script. Imagine working with multiple developers, several plugins and it becomes a real pain in the ass to keep track of configuration changes.
(more…)
Phing 2.4.4 and booleans as strings
A note to self (and hopefully preventing others from having to find this out the hard way): using Phing with booleans as strings may cause unwanted sideeffects. See below for more info:
I’m using a ReplaceRegexp filter to change WordPress’ wp-config.php file. In this file a constant WP_DEBUG is defined false and I would to change it to true. I have defined the regex and provided a property with a string “true”. However this string will be casted to a bool and causes strange sideeffects.
Consider this build.xml example:
<!– setup wp config specific properties –>
<property name=”wp_config.wp_debug” value=”true” />
<!– Setup the wp-config file –>
<!– thanks to http://stackoverflow.com/questions/974963/phing-and-wordpress-configuration –>
<target name=”setup-wp-config” description=”Copies the wp-config-sample.php to wp-config.php and sets up the parameters for the test site”>
<copy file=”./wp-config-sample.php” tofile=”./wp-config.php”>
<filterchain>
<replaceregexp>
<regexp pattern=”(define\(‘WP_DEBUG’, )\w+(\);)” replace=”\1${wp_config.wp_debug}\2″/>
</replaceregexp>
</filterchain>
</copy>
</target>
If you would run this it would not work as expected. Changing the property to “foo” it does work as expected. This is probably related to this thread:
http://phing.tigris.org/ds/viewMessage.do?dsForumId=1083&dsMessageId=958537
Using the workaround in the thread the example becomes:
<!-- setup wp config specific properties -->
<property name="wp_config.wp_debug" value="(bool)true" />
<!-- Setup the wp-config file -->
<!-- thanks to http://stackoverflow.com/questions/974963/phing-and-wordpress-configuration -->
<target name="setup-wp-config" description="Copies the wp-config-sample.php to wp-config.php and sets up the parameters for the test site">
<copy file="./wp-config-sample.php" tofile="./wp-config.php">
<filterchain>
<replaceregexp>
<regexp pattern="(define\('WP_DEBUG', )\w+(\);)" replace="\1${wp_config.wp_debug}\2"/>
</replaceregexp>
</filterchain>
</copy>
</target>
Thus by adding the type (bool) to the property value forces Phing to work correctly with boolean values as strings. Thanks Hans Lellelid for this workaround!
A bug has been filled with Phing. See this ticket #633
<!-- setup wp config specific properties -->
<!-- Setup the wp-config file -->
<!-- thanks to http://stackoverflow.com/questions/974963/phing-and-wordpress-configuration -->
Contactgegevens
Terzijde
The first step — especially for young people with energy and drive and talent, but not money — the first step to controlling your world is to control your culture. To model and demonstrate the kind of world you demand to live in. To write the books. Make the music. Shoot the films. Paint the art.Chuck Palahniuk
