WordPress.org

Ready to get started?Download WordPress

Forums

Simple Subscribe
[resolved] Use of wp_mail (13 posts)

  1. JustinTheClouds
    Member
    Posted 5 months ago #

    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 https://postmarkapp.com/ and http://www.mailgun.com/ 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 AppFog.com 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.

    http://wordpress.org/plugins/simple-subscribe/

  2. latorante
    Member
    Posted 5 months ago #

    Funny thing, was thinking the same thing this morning, ha! :)

    Looking forward to see what you've got.

    Cheers,
    Mart

  3. Breklin
    Member
    Posted 5 months ago #

    Hi,

    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.

    Breklin

  4. latorante
    Member
    Posted 5 months ago #

    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 ;)

    Regards,
    Mart

  5. JustinTheClouds
    Member
    Posted 5 months ago #

    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.

  6. Breklin
    Member
    Posted 5 months ago #

    Justin,

    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!

    Breklin

  7. latorante
    Member
    Posted 5 months ago #

    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.

    Regards,
    Mart

  8. Breklin
    Member
    Posted 5 months ago #

    Mart,

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

    Breklin

  9. latorante
    Member
    Posted 5 months ago #

    Breklin, yes he can share what he comes up with :) that's up to him now innit.

    Mart

  10. JustinTheClouds
    Member
    Posted 5 months ago #

    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.

  11. latorante
    Member
    Posted 5 months ago #

    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.

    Regards,
    Mart

  12. JustinTheClouds
    Member
    Posted 5 months ago #

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

    I tested with the mailgun.com 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
            try{
    
                $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 -- http://core.trac.wordpress.org/ticket/23578
                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';
            }
        }
  13. tamersherif
    Member
    Posted 4 months ago #

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

Reply

You must log in to post.

About this Plugin

About this Topic

Tags

No tags yet.