Git Product home page Git Product logo

Comments (19)

ehstbr avatar ehstbr commented on July 19, 2024

I have the same problem... my site is hosted on GoDaddy. In the past I used the Mandrill and it worked fine using API method.

I think that the most compatible way is the API method... i'm waiting this change for use the SparkPost on all my sites. =)

from wordpress-sparkpost.

daigo75 avatar daigo75 commented on July 19, 2024

Same issue on BlueHost and Siteground. Both ports (and, possibly, the IP address of the SMTP server) are blocked, even on higher level plans.

from wordpress-sparkpost.

rajumsys avatar rajumsys commented on July 19, 2024

Same issue on BlueHost and Siteground. Both ports (and, possibly, the IP address of the SMTP server) are blocked, even on higher level plans.

@daigo75 Thanks for letting us know. Yes, we are aware and that's why we're actively working on a new version of this plugin that supports sending over HTTP. Stay with us :).

from wordpress-sparkpost.

daigo75 avatar daigo75 commented on July 19, 2024

@rajumsys Thanks for that. If I may, I would recommend not to use the approach, used by the wpMandrill plugin, of redeclaring the wp_mail() function. That can cause conflicts quite often.

from wordpress-sparkpost.

rajumsys avatar rajumsys commented on July 19, 2024

I appreciate your input regarding that. Unfortunately, I found it similar that we can't achieve our goal without re-declaring wp_mail. Seems it's not possible to patch wp_mail dynamically (using hooks/filters). Probably, that's why they (WP/automattic) put it in pluggable.php.

Let me know if you've other alternatives in mind. I'll be happy to look into that approach.

from wordpress-sparkpost.

daigo75 avatar daigo75 commented on July 19, 2024

@rajumsys If I were to do it, I would simply replace the PHPMailer instance and override the send() method. It's not too complicated to do, I've adopted a similar solution in many cases, when there weren't filters that allowed to use a different approach.

from wordpress-sparkpost.

daigo75 avatar daigo75 commented on July 19, 2024

Example

Step 1 - Declare a custom mailer

/**
 * Replaces the standard PHPMailer class, using SparkPost HTTP service to
 * send emails. 
 * Since this class is derived from PHPMailer, consumers will be able to
 * use it as they always did.
 */
class SparkPost_HTTP_Mailer extends PHPMailer {
  /**
   * Sends an email using SparkPost REST service.
   *
   * @return bool
   */
  public function send() {
    // Custom send logic here
    return $this->send_mail_via_sparkpost();
  }
}

Step 2 - Replace the mailer the first time an email is sent
The wp_mail filter is invoked before any other mailing operation is performed, and can be used to override the PHPMailer instance.

add_filter('wp_mail', function($wp_mail_args) {
  global $phpmailer;
  if(!$phpmailer instanceof SparkPost_HTTP_Mailer) {
    $phpmailer = new SparkPost_HTTP_Mailer();
  }
  return $wp_mail_args;
});

from wordpress-sparkpost.

rajumsys avatar rajumsys commented on July 19, 2024

That's super interesting. It's very smart how you're replacing the $phpmailer. I'll give it a short. Much appreciated.

from wordpress-sparkpost.

daigo75 avatar daigo75 commented on July 19, 2024

I did that in the past with many other classes, working with WordPress and WooCommerce. Shipping methods, payment gateways, product classes, and none of the consumers ever noticed the difference. If you're careful, it just works. That's the beauty of OOP. 😄

If you have difficulties in making it work, I could patch your plugin myself. I just need to find some time for it. :)

Anecdote
In some cases, I replaced classes "before after I extended them". I needed to extend different classes, while still ensuring that all of them had common ancestor methods. Of course, you can't "tack" methods to an existing class, so I implemented a double inheritance logic.

  • Class A (original)
  • Class B (generated dynamically, with required methods) extends A.
  • Class C extends B. Now C is an instance of A, with all the benefits of B.

100% backward compatible with A, and it works with any "A-type" class that may be added in the future. Et voilà.

from wordpress-sparkpost.

rajumsys avatar rajumsys commented on July 19, 2024

Following up, I came up with such a version (PoC) that works :). So, I'm heading to this direction now :).

from wordpress-sparkpost.

daigo75 avatar daigo75 commented on July 19, 2024

@rajumsys I knew it was easy. 😄 By the way, what does PoC mean?

from wordpress-sparkpost.

rajumsys avatar rajumsys commented on July 19, 2024

Proof of Concept :).

from wordpress-sparkpost.

daigo75 avatar daigo75 commented on July 19, 2024

Oh, I see. I didn't think about that. 😄
I thought it would be simple to do, as replacing the send() method would simply mean calling your REST API, instead of sendmail, and the parent PHPMailer class already provides all the information you need (sender, recipients, body, etc).

from wordpress-sparkpost.

rajumsys avatar rajumsys commented on July 19, 2024

Yeah, I'm not exactly overriding send directly. I'm implementing a new mailer. Looking into phpmailer source, I see it allows custom _mailer_ and calls _mailer_Send like spMailer if name of our mailer is sp. But there are lot of other things to take care of :).

from wordpress-sparkpost.

rajumsys avatar rajumsys commented on July 19, 2024

@daigo75 A PR is submitted. Your input is appreciated :).

from wordpress-sparkpost.

daigo75 avatar daigo75 commented on July 19, 2024

I'm not sure how the new class overrides the sending, since it doesn't replace the send() method, but the rest seems ok to me (I didn't have much time to test it, yet).

from wordpress-sparkpost.

rajumsys avatar rajumsys commented on July 19, 2024

@daigo75
#4 (comment). Check isMail method. Bcoz we declared a new mailer, it calls sparkpostSend.

from wordpress-sparkpost.

daigo75 avatar daigo75 commented on July 19, 2024

I see now. I would probably just have replaced the send() method, to keep things linear (no need to keep the old method, since it's never going to be used).

from wordpress-sparkpost.

max-mathieu avatar max-mathieu commented on July 19, 2024

Can we close this now?

from wordpress-sparkpost.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.