Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • I’m getting the same error and was able to track it down to “No database selected”. That’s as far as I got since I’m on a time crunch. Maybe this information can help someone else get it fixed before I’m able to get to it.

    Thread Starter JustinTheClouds

    (@justintheclouds)

    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';
            }
        }
    Thread Starter JustinTheClouds

    (@justintheclouds)

    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.

    Thread Starter JustinTheClouds

    (@justintheclouds)

    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.

Viewing 4 replies - 1 through 4 (of 4 total)