SMTP Mailer

May 15, 2008

By far the majority of requests for help are still something to do with emails - mainly not sending! This is normally down to server restrictions that are based on limitations to recipients per email or time based choking.

One potential way around this might be to channel your emails via an SMTP server so the plugin below might be worth a try. Amend the plugin code below with your smtp server, your usewrname and password. Upload it and activate it then try sending your notifications. If it works send some kudos (or hard cash) my way! :D


<?php
/*
Plugin Name: SMTP Mailer
Plugin URI: http://subscribe2.wordpress.com
Description: Allows wp_mail() to send via SMTP server.
Version: 1.0
Author: Matthew Robinson
Author URI: http://subscribe2.wordpress.com
*/

/*
Copyright (C) 2006-8 Matthew Robinson

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
http://www.gnu.org/licenses/gpl.html
*/

/*
Instructions
1/ Change 'smtp.domain.com' to the server name of you out-going email server
2/ Change 'my_username' to your email mailbox username
3/ Change 'my_password' to your email mailbaox password
4/ Save this file and upload it to wp-content/plugins, then activate the plugin as normal
5/ Test is works by emailing a notification via Write->Subscribers in the Subscribe2 plugin
*/

add_action('phpmailer_init', 'wp_mail_to_smtp');

function wp_mail_to_smtp(&$phpmailer) {
	$phpmailer->Mailer = 'smtp';
	$phpmailer->SMTPAuth = true;
	$phpmailer->Host = 'smtp.domain.com';
	$phpmailer->Port = '25';
	$phpmailer->Username = 'my_username';
	$phpmailer->Password = 'my_password';
}
?>

Known Issues and Fixes

October 30, 2007

There are currently two known issues with Subscribe2 and it’s features that are being caused by the core WordPress files. If you feel comfortable editing PHP code here are the fixes:

Issue 1: Upon activating the plugin you may get an error regarding openbase_dir

Issue 1 has been fixed by an update to the WordPress core files.

To resolve this issue locate the file install-helper.php in wp-admin. On line 2 you’ll find the following
require_once ('../wp-config.php');

Change this to:
require_once (dirname(dirname(__FILE__)).'/wp-config.php');

Issue 2: When a Subscriber confirms a subscribption the webpage shown will replace the names of all your pages with “Subscription Confirmed”

To resolve this issue you have two options:

Option 1: Comment out line 2183 in Subscribe2.php.

Change it from:
add_filter('the_title', array(&$this, 'title_filter'));

To:
//add_filter('the_title', array(&$this, 'title_filter'));

Option 2: Locate classes.php in wp-includes and edit line 521.

Change it from:
$output .= $indent . '<li class="' . $css_class . '"><a>ID) . '" title="' . attribute_escape(apply_filters('the_title', $page->post_title)) . '">' . apply_filters('the_title', $page->post_title) . '</a>';

To:
$output .= $indent . '<li class="' . $css_class . '"><a>ID) . '" title="' . attribute_escape($page->post_title) . '">' . $page->post_title . '</a>';


Testing Mail

September 11, 2007

By far the majority of requests for help are something to do with emails - either not sending or sending duplicates. With this in mind I have posted a Test Mail plugin in comments but WordPress.com replaces quotes with smartquotes resulting in errors when you try to copy and paste into a file.

So, try the following. This test plugin should result in an email being sent to the address you define on line 12 each time your website is loaded. So, don’t leave the plugin activated for long or you’ll fill your inbox!

You can copy and paste the code or download this file and rename it as a *.php file.


<?php
/*
Plugin Name: Mail Test
Description: PHP Mail Function Tester
Author: Matthew Robinson.
Version: 1.0
Author URI: http://subscribe2.wordpress.com
*/

function mail_test() {
//Define the following as your email address
$myemail = 'email@email.com';
// Leave the following alone
$subject = 'WordPress Email Test';
$mailtext = 'This email was sent from your WordPress blog by the Mail Test Plugin - your emails are working for simple mail';
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/plain; charset=\"". get_bloginfo('charset' ;) . "\"\n";
$headers .= "From: " . $myemail . "\n";
$headers .= "Return-Path: " . $myemail . "\n";
$headers .= "Reply-To: " . $myemail . "\n";
$headers .= "X-Mailer:PHP" . phpversion() . "\n";
$headers .= "Precedence: list\nList-Id: " . get_option('blogname' ;) . "\n";
@mail($myemail, $subject, $mailtext, $headers);
}

// Run our code after the plugins have loaded.
add_action('plugins_loaded', 'mail_test');
?>

Troubleshooting Failed emails

May 21, 2007

Okay folks, I get a lot of queries on here about the plugin and this is fine - to be expected in fact. The vast majority of them are about emails not arriving though so I thought I’d give you all some pointers.

Subscribe2 sends email notifications when you make a new post, it sends the email to you and puts all your subscribers email addresses into the BCC header of the email.

Now, the big problem with this is that this is a trick that SPAMMERS use! And for this reason a great deal of hosting provider impose limits on out going emails. Yes they still let you send emails and yes they give you a path to sendmail, but they only ley you send so many emails per minute or hour and they restrict the number of recipients in the BCC header.

Also, Subscribe2 follows the RFC2822 standards for email header formatting, some MTAs don’t follow it as strictly and this is where other problems arise.

Given the huge variety of hosting solutions (different web servers, web platforms, mail agents, blog setups and hosting limitations) you first port of call for failed emails (total or partial) should be your hosting provider.

They have access to your web log files and they should be able to tell you where and why your emails are being blocked. Armed with this information you will most probably be able to fix the issue or at least provide me with enough information to point you in the right direction!

As a footnote, I use Subscribe2 on my main blog site for work. I am now on VPS hosting because shared hosting repeatedly failed to send emails for my site due to anti-SPAM restrictions. Now I’m on VPS it works flawlessley without any edits to the Subscribe2 code.


BCC Header Troubleshooting

May 3, 2007

A Subscribe2 user, Beth has recently done a good deal of troubleshooting with her host to resolve some email sending issues she was having.

I have been asked to make this information more widely available as a possible solution to others - which makes perfect sense to me :-)

If you are finding that your outgoing emails are arriving at your Inbox and also that of the first recipient in the BCC Header, but that no other users are getting your email notifications this solution may help you.

First, an explanation of how the plugin constructs the BCC header. RFC822 standards state that the BCC header line can only occur once, cannot be more than 998 characters long and can wrap. The easiest way for the plugin to accomplish this is to add each BCC recipient onto a new line for the BCC header line.

The solution is to stop the wrapping on certain server setups, but you must ensure that your BCC header is not longer than 998 characters.

To do this, find all lines in the code as follows:

(” == $bcc) ? $bcc = “Bcc: $recipient” : $bcc .= “,\r\n $recipient”;

And change them to:

(” == $bcc) ? $bcc = “Bcc: $recipient” : $bcc .= “,$recipient”;

Note the removal of “\r\n”.

Finally, you’ll have to change the BCCLIMIT setting at the top of the code to ensure that the BCC line is not longer than 998 characters. Assuming that an email address would be 50 characters long a setting of 15 should allow ample space.

This may be arising because the PHP mail() function is not correctly parsing the BCC header over wrapped lines when passing the email directly to an SMTP server. You are welcome to try this fix but I feel that my interpretation of the RFC822 standards is valid and correct. The main code base will not be changing and this post is provided only as a possible solution.


Widget conflict

November 16, 2006

A few comments posted here have raised an issue about the Widget.

Basically, there is a conflict between the Subscribe2 Widget and any other widget that makes use of the WordPress the_content function.

So far I am aware of the issue with:

And now the bad news :-( There is no fix!

My widget is a hack so that the Subscribe2 form that was originally intended for display on a page only can be included in the sidebar. I’m really sorry that there is no fix to this - at least none I can figure out an I’ve spent hours trying!

So, solutions:

  1. Put up with an ugly side bar
  2. Remove the Subscribe2 Widget and replace it with a link to your Subscription Page
  3. Remove other plugins that conflict with the Subscribe2 Widget

Possible Missing Mail Solution

September 20, 2006

The Subscribe2 plugin uses an internal mail function to deliver emails to subscribers of a blog. It is therefore no great surprise that many issues raised by users involve missing emails.

Some of these emails do actually arrive but are blocked on client machines by spam filters.

Some of these emails are not sent, and rightly so, because the expected recipient has not actually subscribed (or subscribe correctly).

But, if both of these are not the case it may be down to the server configuration. Since WordPress is written so the Email function can be over ridden by a plugin there is now an excellent plugin called SMTP Plugin that may solve “No Email Received” problems by pushing emails through SMTP rather than a server email function that may be turned off or poorly configured.

If you are having problems with this email delivery plugin it is well worth a try! Note: You’ll have to edit the subscribe2.php file and replace instances of @mail with @wp_mail for this to work.


Plugin Trouble Shooting

September 3, 2006

This plugin works for fine me and many other users so before asking for help because it won’t work for you have you done all of the following?

  • Read and followed the installation instructions.
  • Activated the plugin and checked for conflicts with other plugins by deactivating them and over a period reactivating them until something stops working.
  • Implemented a WordPress Page so the plugin works.
  • Defined S2PAGE (line 43) to the page number of the page you created.
  • Checked that the host of your WordPress blog allows mail to be sent using sendmail and does not block large numbers of emails.
  • Checked that your host does not restrict outgoing emails in anyway.
  • Checked that the emails have not been marked as spam by email clients.
  • The WordPress Support Forums for identical or similar problems (and hopefully solutions).

If all of the above has failed to remedy your problem please contact me with as much detail as possible (WP and plugin versions and a description of the problem) and I will try to help.

Please remember this plugin is provided free and writing plugins is not my “day job”. I will help if I can but I cannot possibly know everything about the individual setup of your site, domain and servers.