Support » Plugin: Simple Subscribe » Use of wp_mail

  • Resolved JustinTheClouds


    First off, great plugin. It is just what I was looking for. Thank you.

    I think you should convert your sendEmail method located in Email.php to using the wp_mail method instead of Nette’s mail class.

    This change will allow plugins that tie into wp_mail to send mail using APIs to continue to work along side your plugin. I use and on some of my sites and both have plugins that tie into the wp_mail function.

    This is the route for sites that are hosted on servers that don’t support SMTP such as or even on localhosts that aren’t SMTP configured.

    I’m working on this change now but I’d definitely like to see it added so updates don’t break my change. Once I get it working, I’ll share the code.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Funny thing, was thinking the same thing this morning, ha! 🙂

    Looking forward to see what you’ve got.



    I just came across your plugin for a new blog as it has all of the features we are looking for except it’s inability to work with WP_MAIL which we require since our SMTP server is authenticated under SSL. I am looking for a work around, such as installing PEAR, but would very much like to see compatibility with WP_MAIL implemented in an update!

    The plugin looks, great so far, by the way.

    I’ll be keeping my eyes out for an update.


    Hi there mate,

    yes as I said before, it’s probably the best idea, but for now, I don’t have time to implement it 😉


    I’m hoping to get some time later today or tomorrow to implement this. I’m quite busy as well but once I get some spare time I’ll definitely share what I work out.


    That would be great. I’m looking at it, too, however I’m just as swamped. I was hoping to be able to look further into it this evening.

    Please do share and I will, too, should I come up with a viable solution.

    Thank you!


    Justin, my man …

    I thought you were implementing that yourself haha. Right, later today, or tomorrow? No I don’t think that will do it, I work 12 hours a day now … barely have time for gym and me guitar etc… nor have I time for Simple Subscribe. I reckon I’ll have some time in 2 weeks time.



    Can he not share what he comes up with as a work-around until you are able to attend to an update?


    Breklin, yes he can share what he comes up with 🙂 that’s up to him now innit.


    latorante. Didn’t mean to imply that you were supposed to be the one writing it. lol. You got the hard part out of the way. I can handle this one.

    Nice one,

    Justin – yes I will write it, as I said, but not now – because I’m busy. In the time being, if it really helps you both, you can help each other out and maybe someone else here, looking for same anwser, before I rewrite to use wp_mail.


    Ok, here is what I came up with. Only tested on localhost so far but shouldn’t make a difference.

    I tested with the api plugin installed which utilizes wp_mail.

    Also if anyone else uses the modification, can you test to make sure it still works normally with SMTP. Since my server does not support it.

    This is located in SimpleSubscribe/Email.php on line 199
    I rewrote the sendMail method and had to add a setWPMailContentType method. Please test before production use.

         * Here's the magic
         * @param array $recipients
         * @param null $subject
         * @param array $data
         * @throws EmailException
        private function sendEmail($recipients = array(), $subject = '', $data)
            // recipients check
            if(!is_array($recipients)){ $recipients = array($recipients); }
            if(count($recipients) < 1){
                throw new EmailException('No subscribers provided. (possibly none in your system)');
            // try sending e-mail
                $headers = array();
                $headers[] = 'From: ' . $this->senderName . ' <' . $this->senderEmail . '>';
                foreach($recipients as $recipient){
                    $headers[] = 'Bcc: ' . $recipient;
                // set HTML / or plaintext body
                add_filter( 'wp_mail_content_type', array($this, 'setWPMailContentType') );
                // Send the mail
                wp_mail( $recipients, $subject, $this->getEmailTemplate($data));
                // Reset content-type to avoid conflicts --
                remove_filter( 'wp_mail_content_type', array($this, 'setWPMailContentType') );
            } catch(\Exception $e){
                throw new EmailException($e->getMessage());
         * Return the content type wp_mail should be set to
         * ** This is defined as it's own function so we can remove_filter after use
        public function setWPMailContentType() {
            if($this->htmlEmail == TRUE){
                return 'text/html';
            } else {
                return 'text/plain';

    Thank you Justin!!
    This works quite well with me, I use SendGrid for sending emails.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Use of wp_mail’ is closed to new replies.