Hacking WP-EMail

WP-EMail is one of the many Wordpress email plugins that I decided to use in my recent project. Installation instructions were pretty straightforward but after filling out the fields and hitting the submit button I received a “Language failed to load: instantiate” error. I then decided to look for support in their forum and I landed here. I followed all the suggestions in the forum and exhausted all of the options for configuring WP-EMail but still there were all these different errors coming out.

Thats when I decided to go back to PHP basics of sending email to check if the server is really capable of sending one. I opened up the PHP manual and used this basic code:

$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
 
mail($to, $subject, $message, $headers);

Fortunately it worked. If that little snippet worked then I could replace the existing code from the plugin and replace it with this basic one because all the plugin has to do is send out an email. (I have to include headers because in some cases in different servers the PHP mail function wouldn’t work without it) I then opened up email.php (inside /wp-content/plugins/email/), went to line 881 then edited it to:

if (mail($to, $subject, $message, $headers)) {

Then just above it I declared the mail function variables and assigned the variables used in the plugin like this:

$to = $friendemail;
$subject = $template_email_subject;
$message = $template_email_bodyalt;
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

Also don’t forget to set the send email method to “PHP” in the email options. This kind of editing will ignore the PHPMailer class that the plugin is using and hopefully send that email to your friend.

As always I’m open to your suggestions and violent reactions and if you know any other alternatives in tweaking WP-EMail please don’t hesitate to share it. Thanks for reading and you can see a live example of what I’ve discussed here.

Many thanks to Lester Chan for developing this great plugin! I hope to hear your thoughts regarding this fix.

Comments

One Response to “Hacking WP-EMail”

  1. GaMerZ on March 31st, 2008 9:51 am

    Thanks for the compliments =D

    Just to add, you can always make use of PHP to send email. WP-Admin -> Email -> Email Options -> “Method Used To Send E-Mail:”

    The reason why PHPMailer throw you this error is because it has problem instantiating a channel (Sendmail, PHP or SMTP) to send the email.

    The language string error can be ignored because WP-Email/WordPress did not include any languages for PHPMailer within the distribution.

Leave a Reply