Jump to content

WireMailgun - An Alternative


nbcommunication
 Share

Recommended Posts

Hi, that could effect the count I think. I’m pretty sure it should be an associative array argument, so it would be $to[$emailAddress] = “”; (name omitted)

I can’t actually see the implementation of the argument in WireMail::to() here - https://processwire.com/api/ref/wire-mail/to/ - on my mobile, but it should behave in the same way when using it with WireMailgun.

Looking at the WireMail.php source I think maybe a sequential array is accepted - will need to look at this further! 

Link to comment
Share on other sites

@nbcommunication - I finally figured out the extra send / count issue. We had 24 subscribers with uppercase characters entered in their email address. If I do a strtolower() on each address before building up the "to" and recipient variables arrays, everything works as expected. I am not sure if this is a bug in Mailgun, PW, or this module. Any thoughts?

Link to comment
Share on other sites

4 hours ago, nbcommunication said:

Yep, that'll do it

But why - I don't really understand the problem. Arrays can have keys with uppercase characters - why are we ending up with the original and an extra entry with a key that is all lowercase?

Link to comment
Share on other sites

  • 3 weeks later...

Hi @adrian,

Finally gotten a look - it was as I expected.

When an email address is passed to WireMail::to() it is run through WireMail::sanitizeEmail(). This passes the email through both strtolower() and trim().

addRecipientVariables() was just using Sanitizer::email(), which doesn't pass the email through strtolower/trim, resulting in different keys. I've changed it to use sanitizeEmail().

Sorry it's taken so long to fix!

Cheers,

Chris

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Hi @nbcommunication and @adrian,

I'm evaluating to use WireMailgun both throughout my ProcessWire website and in combination with ProMailer, and would like to know some more about it.

In the WireMailgun module README is written: Extends WireMail to use the Mailgun API for sending emails.

My question is: once installed, will WireMailgun be used on demand ("activated" per request, so I can continue using PW WireMail normally and benefit of Mailgun features through WireMailgun only when needed) or will it someway substitute or replace PW WireMail functionalities at all (so I have to explicitly "deactivate" WireMailgun in all cases I don't need Mailgun features)?

 

Link to comment
Share on other sites

@adrian So, it looks like that the WireMailgun module (not the WireMailMailgun one) is "not invasive" and "mostly compatible". That is, I can use WireMailgun "on demand"/"activated per request" and it works with ProMailer and other Email/WireMail modules - Wire Mail SMT - except the WireMailMailgun modules developed by plauclairgebeer and outflux3 (from READMEWireMailgun is not compatible with these other versions).

Please confirm this or correct me if I'm wrong.

 

Link to comment
Share on other sites

@LAPS, @adrian - I only use WireMailgun and don't use ProMailer, so I'm not the best person to check with...

However, as I understand it, any WireMail module installed supersedes the core WireMail functionality. For example, system error / forgot password emails we receive are sent through Mailgun.

I've no idea how multiple WireMail modules are handled, but I assume that ProMailer gives you the option to choose which to use?

Cheers,

Chris

Link to comment
Share on other sites

2 minutes ago, nbcommunication said:

@LAPS, @adrian [...] as I understand it, any WireMail module installed supersedes the core WireMail functionality. For example, system error / forgot password emails we receive are sent through Mailgun.

One of my doubt is about how WireMailgun does work. For example, how it supersedes the core WireMail functionality?

 

2 minutes ago, nbcommunication said:

[...] but I assume that ProMailer gives you the option to choose which to use?

I confirm that ProMailer gives you the option to choose which WireMail module to use, and I assume that WireMailgun will be the option!

Link to comment
Share on other sites

Hi @LAPS,

Have a look at new() in WireMailTools. This is where the WireMail module is set either explicitly through a passed option or config setting, or inferred.

Going by your first post, I think you may be able to set $config->wireMail, so it just uses default WireMail.

Cheers,

Chris

Link to comment
Share on other sites

@nbcommunication It may be useful to add the below text to the README documentation, if the case:

Optional

If WireMailgun is the only WireMail module you have installed, then you can skip this step. However, if you have multiple WireMail modules installed, and you want WireMailgun to be the default one used by ProcessWire, then you should add the following to your /site/config.php file:

$config->wireMail('module', 'WireMailgun');

In a similar way as made for WireMailGmail.

Link to comment
Share on other sites

  • 1 month later...

Hi @LAPS,

Campaigns isn't something I have experience with, but is it not a reporting system in Mailgun for analysing/comparing messages?

From what I can gather, this uses message data and/or tags to do this, both of which are already implemented in the module. There isn't anything available in the API specifically related to campaigns.

Is there another implementation you'd like to see, something like a setCampaign() method which adds the message data?

Cheers,

Chris

Link to comment
Share on other sites

Hi @LAPS,

I've added a setCampaign() method. It is essentially an alias for addTags(), but takes multiple string arguments instead of an array like addTags().

<?php

$mg->to("an@email.com")
  ->subject"A Subject")
  ->setCampaign("campaign1", "campaign1-a", "testing")
  ->bodyHTML("<p>A Message</p>")
  ->send();

It also enables open and click tracking by default, as this is presumably behaviour you want for campaign analytics. If this isn't required, using addTags() is the way to go, but you can also pass false as the first argument to disable this behaviour and use whatever tracking settings you have by default.

Cheers,

Chris

  • Like 1
Link to comment
Share on other sites

  • 3 years later...

Hello,
I try this module in php 8.1 environment, using processwire forgot password module :

Fatal Error: Uncaught Error: Undefined constant "CURLOPT_POST" in /var/www/domainname/public_html/www1/site/modules/WireMailgun/WireMailgun.module:730 Stack trace:
1. /var/www/domainname/public_html/www1/site/modules/WireMailgun/WireMailgun.module(640): WireMailgun->apiSend()
2. /var/www/domainname/public_html/www1/wire/core/Wire.php(413): WireMailgun->___send()
3. /var/www/domainname/public_html/www1/wire/core/WireHooks.php(952): Wire->_callMethod()
4. /var/www/domainname/public_html/www1/wire/core/Wire.php(484): WireHooks->runHooks()
...

Maybe not compatible with php 8 yet ?

Link to comment
Share on other sites

  • 7 months later...

@nbcommunication or anyone else ever seen this error in the "wire-mailgun" log?

'recipient-variables' parameter is not a valid JSON

$recipientsArr[$emailAddress] = [
     'id' => $recipient->id,
     'email' => $emailAddress,
     'first_name' => $recipient->first_name
];

$mailer->addRecipientVariables($recipientsArr);

It happens during a loop of email sends - there are lots of different emails, each sent to one or a few people so the emails are sent in batch mode, but it seems like only one of the emails in the loop actually triggers this error. I feel like perhaps there is something weird with the first name for one of the recipients (maybe a strange character or something), but before I pull all my hair out, I was hoping to hear that someone else had already come across this and know what to look for :)

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...