Sending automated emails which don’t get blocked by ISPs

Published:
September 5, 2007 @ 12:38 am
Category:
PHP,Server Administration
Author:
Chris Wheeler

I’ve recently come across a problem where automated emails are getting blocked by a number of ISPs. I’ve tracked this down to the sender verification methods some ISPs use – If an email comes from an address which isn’t an active mailbox on the server, it is sometimes dropped without any notice to the sender or recipient.

A fair few web sites send automated emails from addresses such as no-reply@domain.com do-not-reply@domain.com forum@domain.com etc – if these accounts are not setup the mails will be discarded by some servers.

You should always use a real email account to send emails – even if it silently discards all incoming mail.

Another problem is that if PHP’s mail() function is being used, and php is running as the userĀ ’nobody’, emails by default will be sent from nobody@hostname.isp.com – which in most cases does not exist.

The way around this is to specify the senders email address through the mail function. e.g.

mail($to, $subject, $body, $headers, '-f sales@domain.com')

Note: Even if you have set the ‘From: ‘ field in the email headers, the email envelope address may still be set to a different account, using the ‘-f email@address’ parameter will fix this, and your emails should reach your customers!

Integrating WordPress into Smarty

Published:
May 16, 2007 @ 11:49 pm
Category:
PHP
Author:
Chris Wheeler

While searching for a way to integrate WordPress into an existing web site, all the tutorials I came across were aimed at users who wanted to make WordPress look like their existing site. There were also some tutorials on how to take parts of the WordPress engine and add them to existing PHP pages, however; I couldn’t find anything on integrating WordPress with Smarty, so I thought I’d have a go – and it turned out a lot easier than I thought.

Step 1: Install WordPress

Download WordPress and install to a directory on your web site – this will be the final url which visitors will see. I chose /blog/

Step 2: Create custom PHP includes

Now you need to create two PHP files, which provide ‘The Loop’ (the code which provides the content for all blog pages) and the sidebar links. Credit for this goes to the author of this article.

The two files I created were:

/blog/custom/the-loop.inc.php

View the-loop.inc.php

This is basically just /blog/wp-content/themes/classic/index.php with get_header() and get_footer() removed.

/blog/custom/sidebar.inc.php

View sidebar.inc.php

This is basically just /blog/wp-content/themes/classic/sidebar.php
You could most probably just include the sidebar.php file from the classic theme, but I wanted to remove a few sections

Step 3: Include the WordPress header

The WordPress header file needs to be included on all pages which have blog content on them, I simply placed it into my ‘header.php’ file – as this is included on all pages

require_once './blog/wp-blog-header.php';

Step 4: Create the Smarty PHP files

To show the main WordPress content inside of your sites design, you need to create a PHP file and template. My file looks something like the following:

blog.php

View blog.php

The $page variable is simply an instance of the Smarty class, which is instantiated in the header.php file, the page title is set and then the blog.tpl file is parsed.
The ‘if’ statement checks to make sure the page isn’t a Rss, Trackback or Robot – as in these cases we do not want to send any html output, as output has already been created by the WordPress header.

Step 5: Create the Smarty TPL templates

To pull in the main WordPress content area into your smarty templates, use the following:

blog.tpl

{include file="html_header.tpl"}
{include file="layout_header.tpl"}  

<h1>Blog</h1>  

{include_php file='blog/custom/the-loop.inc.php'}     

{include file="layout_footer.tpl"}
{include file="html_footer.tpl"}

The html_header, layout_header, layout_footer and html_footer template files contain the XHTML which provides the layout for my site.

You can include the sidebar content anywhere on your side, but keep in mind that it can become quite long, and have multiple nested lists depending on how you set up your categories.

sidebar_blog.tpl


{include_php file='blog/custom/sidebar.inc.php'}

Step 6: url re-writing with .htaccess

To make sure your blog.php file is used instead of the default /blog/index.php, add the following .htaccess rules.

RewriteEngine on
Options +FollowSymlinks
RewriteBase /     

RewriteRule ^(.*)blog$ $1blog/ [R=301,L]
RewriteRule ^(.*)blog/$ $1blog.php [L]

If you want to use URL re-writing for permalinks within WordPress, add the following lines to your .htaccess after the above lines

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)blog/(.*)$ $1blog.php [L]

You should with any luck now have WordPress integrated into your Smarty powered site!