Testing Mail

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: https://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');
?>

73 thoughts on “Testing Mail

  1. I’ve found one way to ensure that Subscribe2 sends mails on every posting is to make sure at least one Category box is ticked in the right-hand menu of the “New Post” screen.

    If I don’t tick a box before clicking “Publish” no mails get sent. If I do tick a category box then the mails are sent perfectly.

    FYI: I’m using an unaltered install of the latest Subscribe2 build.

    Rick

  2. As Expected this test mail plugin did send out emails to me everytime I loaded my blog. But strangely the notification emails are not sent. I’m going to enlist all the active plugins on my blog to give you an idea of possible clashes

    Active plugins:
    —————
    Adsense Deluxe 0.8
    Advanced Admin Menus 2.2.1
    Akismet 2.0.2
    All in one SEO pack 1.2.7.4
    Del.icio.us cached 1.2.1
    External Links 2.9
    InSeries 3.0.5
    Live comment Preview 1.7
    LMBox Smiley’s 3.2
    Peter’s Date Countdown Widget Style Yo! 1.93w
    Post/Page Update Notification 2.2
    Snap Shots™ Plugin 1.3
    Sneaks Peak 1.7
    Spam Karma 2 2.3 RC1 -2
    Subscribe2 3.7
    Tag Cloud widget for UTW 1.0
    Ultimate Tag Warrior 3.14159265
    Punkymood Widget 0.2w
    WordPress Database Backup 2.1.2
    WP-ContactForm 1.4.4
    WPG2 2.10
    WPG2 Image Block widget 0.3.1

  3. Tried and tested everything… Manually mailing (write >> mail subscribers) function works and that is what I plan to use for the time being until there is a new version of the plugin or wordpress is released.

    OR

    I might downgrade to version 2.36 which worked…

  4. I’m testing subscribe2 and the problems or the cause that Subscribe2 sends a duplicates mails is produced only if you save the configuration more times.

    For example if you change a “once daily” and save the settings, before you change anything more and save the settings and before you change anything more and save the settings … you have changed tree times the settings and you will receive 3 duplicates of the emails but if you don’t save the setting nevermore you will receive only one mail the next time.

    CIAO

  5. Pedro,

    I’m not sure why you are seeing this sort of behaviour as the plugin clears the CRON events each time you click submit beofre it sets the CRON event for next time.

    I certainly can’t reproduce this behaviour on my setup😦

  6. Tim,

    This appears to be a problem with WordPress making each single / a double /! I’ve reported it to the WordPress.com folks. In the meantime you’ll have to manually edit the code to replace each double slash with a single one.

  7. That did the trick thanks – I get e-mail fine using your test plugin. But still no updates using Subcribe2 – I tried the category trick above and still nada.

    Any ideas?

  8. Tim,

    Have you checked with your host that they don’t have restrictions in place on out going emails. Ask them to check the server logs and tell you why the emails fail.

  9. I seem to have a slightly different problem. Mail is sent fine to public subscribers, but only o the first registered subscriber. I thought it may be the BCC header issue mentioned earlier, but as it seems only to effect registered users, I can’t see why this would be the problem. Unless public users are handled by a different function then registered ones? Do you have any troubleshooting suggestions?

  10. Steven,

    Public and registered subscribers are dealt with in the same mail() function but are collected from different databases. We’ll need to check that your Registered users are returned to the plugin correctly.

    Look for the following line in the publish function:

    $registered = $this->get_registered("cats=$post_cats_string&format=text&amount=excerpt");

    After it add the following:


    mail('your@email.com', 'Registered Users', explode(',' $registered));

  11. $registered = $this->get_registered(“cats=$post_cats_string&format=text&amount=excerpt”);

    After it add the following:

    $this->mail(‘your@email.com”, ‘Registered Users’, explode(‘,’ $registered));

    When I insert the code I receive:

    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in wp-content/plugins/subscribe2/subscribe2.php on line 438

  12. Steve,

    Sorry about that – there are typos in the line I posted – corrected above now, but for completeness it should ahve been:

    mail(‘your@email.com’, ‘Registered Users’, explode(‘, ‘, $registered));

    Make sure to replace your@email.com with a valid email address you can access.

  13. Hello,

    1. The fix to make the test plugin work is converting the dual-BACKslashes to one BACKslash and NOT dual-forward slash to one forward-slash as you noted.

    2. I also have the issue that there are confirmed subscribers – but they don’t get email for new post, even with at least one category selected for the published post…😦

    3. Another thing, what is the different between “confirmed” and “registred” subscribers?

    Thanks.

  14. Another thing, it will be nice if the subscriber will get a final confirmation email after a sucessful subscription, including a link to the subscription page, if he/she will ever wish to unsubscribe.

    Thanks.

  15. Excellent script. Quick Q. How can I remove the brackets in the subject line? Commented out what lines in the code that appeared to be it did not work. Please help.

  16. Hey, also forget about qestion #2, my bad mistake – I installed version 4.0 on wp 2.2.2 …
    I removed it and installed 3.8 and now it works fine.
    BTW, you can simply put the correct above script into a .txt file and publish it here for users to download and simply ask them to rename its extention to .php .

  17. Eitan,

    Glad you answered so many of your own questions – it save me typing!🙂

    The other way to sort out the Test Mail Plugin is to use the Copy to Clipboard link which copies the correct php text. It’s only displayed incorrectly because of the WordPress.com filters😦

    It is possible to add a confirmation email by editing the code at the activate function. This is not something that I’ll put into the main code as I already get enough queries about non-sending emails without adding yet another one!

  18. Alexander,

    You need to edit the code and it depends on whether you are usign per-post or digest emails.

    Look for $s2_subject at the end of the code for per-post and removed the [and the ].

    Look for the subscribe2_cron function and edit the $subject line if you are using digest posts. Be more careful here as the string is multipart so you could generate a fatal error if you mess it up.

  19. Alexander,

    I use a variable in the code ($post_cats_string) to contain a string of the categories to which a post is assigned, you could make use of this string but if you are sending digests you are likely to make a mess as it’s in a loop.

    Your on your own on this one – happy hacking🙂

  20. Hello,

    Sory but I don’t understand how to get that plugin working despites reading the comments above and using the ‘copy to clipboard’ option.

    I have the following error:-
    Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in D:\xampp\htdocs\blog\wp-content\plugins\testemail.php on line 17

  21. Thanks – plugin is ok now.

    I’m still not getting emails. I have WP installed on a windows servr and i need to use the SMTP protocl so I have installed WP-Mail-SMTP succesfully.

    Can Subscribe2 work with SMTP?

    Many Thanks.

  22. Esieens,

    If the testemail plugin is not working then there is something not configured correctly on your server.

    Even to send via SMTP froma server requires you to be running a Mail Transfer Agent like sendmail. You’ll have to google and find out what you need to set up.

  23. I’m running WP on a windows box.

    I have the WP-Mail-SMTP plugin setup – works fine.
    I have also a gallery2 installation on that server and I can send mails using SMTP just fine.

    It works by just connecting directly to my ISP SMTP server.

    So I found out that if I replace the $mail call in the test plugin by a $wp_mail call then mail is sent fine.

    I’m not a PHP guru so I’m not sure if I could get the subscribe2 plugin working by making the same kind of change in that plugin. However looking at the code I guess not since the subscribe2 plugin seems to be using the $wp_email call.

    Comments?

    Many Thanks for your assistance.

  24. esieens,

    I think you could be onto something here. Subscribe2 recently abandoned using wp_mail due to some bugs in the code affecting some of the notifications.

    Look through Subscribe2.php and replace @mail with @wp_mail and you should be good.

  25. Hello Matt!!

    I see you’ve been feeling a bit crummy lately…I’m so sorry to hear that!

    I have been getting complaints about my readers not being sent notices of new posts so thought I’d check back with you to see if you’ve posted any updates.

    I deactivated my Subscribe2 plugin and installed version 3.8 (I’m using WP 2.2.2). I reactivated the plugin and set it up.

    The only thing I’m not sure about is the Mail Test Plugin. I copied and pasted the code into notepad and called it MailTest.php and put it in a MailTest folder. I put my e-mail address in line 12 in the code, then I uploaded that folder into the WP plugin directory, and then went in and activated it. Am I a moron or is that right? When should this test plugin send a message? (Not sure what you mean by “when the page loads”.

    How does this plugin work with Subscribe2 to tell me that Subscribe2 is working okay?

    Thanks for your help Matt. As usual, I appreciate it alot!

    Regards,
    Dave

  26. Hello – I looked at my subscribe2.php.
    I’m using version 4.0.

    Line 506 is a call to @wp_mail so I don’t think this is the problem.

  27. Dave,

    The test email plugin doesn’t really work with Subscribe2 but can be used to diagnose total email failures on your server setup. If the test plugin works (it links into a hook that gets called on every page load of your site) then the issue may be down to things like spam filtering or email limitations rather than non-availability of email.

    If some of your users are not getting notifications get them to check their spam box and you should check you email and error logs on the server.

  28. I am able to get e-mail using testmail.php but still, no subscribers are getting updates. I’ve checked with my host (dreamhost) and they say that everything is working as it should and there is nothing in the log files.

    Thoughts?

  29. Josh,

    Dreamhost are one of the worst for email restrictions! They limit the number of BCC recipients to 30 per out going email – or they used to! I’m surpirised they didn’t know this🙂

    Try looking in the code for the line:

    define('BCCLIMIT', '0');

    and change the 0 to 25 and see if that helps.

  30. For what it’s worth, I didn’t change anything it everything worked just fine.

    I suspect I know why. The first post was a scheduled post and the second post was published in real time. Would that be the issue?

  31. Sorry about the typos. That first sentence should read: “For what it’s worth, I didn’t change anything and it worked just fine.”

  32. First, I wanted to thank everyone for their input on this plugin, especially the authors! I’m having a problem that I’ve not yet seen posted. I’ve confirmed that I am able to receive emails through this plugin. But when I test the system by adding a new user, I am not able to see any categories under the Subscribed Categories section; there are checkboxes present, but no text next to them. And it still doesn’t work if I check both boxes before submitting. Any ideas?

  33. Ryan,

    Please make sure you are using the correct version of the plugin for your version of WordPress. What you describe is what happens when the category functions don’t work correctly becuase of core changes in the tables.

  34. I’m getting the following note in my emails when sending out a newsletter:

    x-php-formmail: yes

    but my subscribers are not receiving my updates. i don’t know why….

  35. I’m getting a white page after activating the test email plugin. I have to delete the test_mail.php page from FTP to get my plugins page back. any ideas?

  36. Hi there,

    Blimey, my eyes have gone all squiffy after reading all these comments…

    However, I still can’t find the solution to my problem! A little while ago, for no discernible reason, subscribers to my blog stopped receiving emails (as did I). Thinking that it was probably time to upgrade the plugin and the version of wordpress I was running, I installed the latest version of both (WP 2.3.1 and S2 4.2).

    This hasn’t helped, and the testmail plugin isn’t working either (and yes, I have downloaded the word version and renamed, adding my email).

    I wonder if it’s something to do with the fact that none of my subscribers are confirmed (they’re only listed as ‘Registered users’, or does this matter?). How do I confirm them?

    Sorry to be a pain, but I’d be really grateful if you’ve got any advice…

    Best,
    Jon

  37. Jon,

    If the TestEmail plugin isn’t working either you’ll need to contact your host. It’s a sign that even simple emails are being blocked for sending via sendmail. Only your host can tell you why and if/how to enable sending.

  38. Hi there, I have been using the plugin for a very long time now. I am on WP 2.3.1 and plugin version 4.2. I have gone through all the help files, faq’s, hacks etc.. and still have the same problem : Subscribe2 is sending duplicate emails. Everytime someone subscribes or a post is published, the email to notify a user or myself is sent twice… any ideas!!?? Thanks. Matt.

  39. Pingback: WordPress Plugins Database » Plugin Details » Mail Test

  40. To fix the multipile email sending problem is quite simple.

    On the Users page, change the notifiction settings to plain text and excerpt only. And Save

    Now go to the Options page > Subscribe 2

    Change the Auto-subscribe users to receive email as: to Html

    This will fix the problem, your users will only receive one email in html format and it will only contain part of the post, they will have to visit your blog to read the full article.

    I think this may be a bug in the program which is causing this error, but these steps fix the problems.

    Hope this helps everyone

  41. I’m getting duplicate emails during post creation, but only to the post author. I’m running WP 2.3.2, and the plugin version is 2.4.4. No matter what the settings, the author always receives a plain text AND an html notice.

    Also strangely, the first and second emails are timestamped differently. The html email always predates the plain text by 5 minutes or so.

    Is this normal behavior? Thanks in advance…

  42. Not sure what I did to resolve it, but now I’m only getting one email. I’ll backtrack and post the results when I find it.

  43. Danno,

    The author may get 3 or more emails depending on subscribers and settings.

    1 for plain text excerpt
    1 for plain text full post and
    1 for HTML email

    There may also be more than one of each of these if the BCCLIMIT variable is used.

  44. Danno,

    It’s not really redundancy, each of the emails is a different format and to preserver subscriber privacy the email is sent to admin with subscribers addresses in the BCC header.

    It’s also quicker to arrange the emails this way so that the mail transport agent handles the mailing rather than sending an email to each subscriber individually from the plugin.

  45. Hi,

    Well, I too have searched and searched all the posts and I am not getting anywhere with my problem. I have subscribe2 4.4 on WP 2.3.2 with about 250 public subscribers. They are supposed to receive a weekly email, but they nor I receive blog updates. I have contacted my host provider and they say nothing in the logs indicate a problem. I have also run the test email and it worked fine. I downloaded wp-cron plugin and used the reminder plugin and that worked as well. The emails just aren’t being sent. I am not a php expert but I don’t mind going in and editing if I have specific directions. Any help would be appreciated. I figure the answer is out there somewhere but this is an act of despair! Thanks everyone.

  46. Yaz,

    Sorry but I only host this site in English as I’m not conversant enough in any other languages (except perhaps PHP and HTML). Try Googling for translations.

  47. I wanted to avoid sending in this post… but I am miffed.

    Firstly, I ran the Test Mail plugin, and it works fine. Getting an email every time a person hits my sight.

    I tried taking my S2 version back a couple notches, and still, no emails are going out to the few readers that I have, except one… me. When I publish something, I get an email stating that I have published a new article, but no one else does. I have tried adding new email listings to see if that helps, but no luck.

    I am sure that this is a settings issue, and I am probably going to be embarrassed when you tell me how to fix this. But I am willing to take that chance.

    TIA!!!

  48. Samuel,

    The first thing to try is look for the 3 instances of @wp_mail( in the subscribe2.php file and change these to @mail(. This will bypass the WordPress mailing system.

    Nest you could try the hint here.

  49. UPDATE….

    When I attempt to send a message to all subscribers, the only one that is sent is the one to me. No one else gets an email, not even the test email accounts I set up for this.

    One of the email addresses I tested with an email tracking program (readnotify.com) and it does not see that the email was aver sent.

  50. OK… Let me look at that and get back to you. The only thing that puzzles me is that this was humming along fine until just recently… so I am supposing that this might have happened during one of the updates.

    I will reply with my results. Thanks for the help.

  51. OK… That looks like it might be it. I am still wondering why it worked fine for so long, then farted on me.

    In the future, is there something I should keep my eyes open for with respect to updates or new releases? Is this something I was doing wrong?

    Thanks for your help… I am going to keep an eye on it for a while before I get too happy.

  52. Samuel,

    I try to post details of what I’ve changed with each new release – look for anything relating to email headers or wp_mail().

    You weren’t doing anything wrong but it seems that wp_mail doesn’t handle BCC headers well on all server setups.

  53. Thanks for the help… It is much appreciated.

    I know these things are offered without warranty, but I am very happy with the fact that you come to bat when we need you.

  54. Thanks for your work,

    I had the problem of sending just one mail to the first suscribed but not to the other. I solved the problem by changing the function wp_mail to mail.
    However now it seems that it is the other way round, all the others received the mail but not the first one.

    Do you think it will be possible to fix it in the next versions or should we keep an eye on that every time we update?

    Thanks again for your help.

  55. Jrumol,

    I’m hoping to get a fix into the next release but wp_mail() may not work reliably on all server set ups so it’s worth keeping an eye on.

  56. I get this:

    Parse error: syntax error, unexpected T_CLASS in /home/fhlinux150/f/fight-2-see.co.uk/user/htdocs/wordpress/wp-content/plugins/test.php on line 17

  57. Simon,

    There is no class in the code above so that’s a weird error. Try copying the code again into a fresh file.

    Note: Posted from holiday hotel wifi!🙂

Comments are closed.