Custom Form & Email Trigger - PHP Warnings - Email aren't sending


(Robin Bilney) #1

Hi,

 

I'm having troubles getting Matrix to email. I've set up an asset builder that should trigger an email when the asset has been built and also a basic custom form that sends an email on submission.

 

I'm getting the following PHP warnings:

 

[2:php warning][R] (/fudge/general/www.inc:115) - preg_match(): Compilation failed: invalid range in character class at offset 151

 

[2:php warning][R] (/fudge/general/www.inc:118) - preg_match(): Compilation failed: invalid range in character class at offset 104  

 

Has anyone experienced this before?  Have I missed something on the sendmail setup?

 

Thanks,

Robin.


(Robin Bilney) #2

Further to this problem, I've tried to set up an Account Manager page that sends a validation email when someone registers but I'm getting the following front-end error message:

 

Your account was not created. Ensure you have entered a username and password and try again.

  • Email is required to send the validation email

 

The trigger that sends an email once an asset is built (mentioned above) successfully fires according to the system log. But no email is sent.

 

 

We can send an email using the command line on the server.   In Matrix's External Tools Configuration the path to the sendmail appears.  Are there other Matrix or server settings that need to be set?

 

We are using Matrix 5.1.9.0

 

Thanks,

Robin.


(Chiranjivi Upreti) #3

Hi Robin,

 

Looking at the code around the the PHP notices you are getting, it appears that the email you are entering is generating invalid regular expression when validating the email. Due to which the email attribute is not getting set and hence Matrix is not sending the email to the user since its email didn't got validated (and probably didn't got set in first place).

 

Can you check the user asset created and see if its email attribute actually got set? Also what is the email address you are entering that is causing this issue? I am assuming this happens with some specific email address formats only?

 

However regardless Matrix should appropriately handle the error regarding the invalid regex generated when validating email. If you can give me an example of email address, I can try replicating locally.


(Robin Bilney) #4

Hey Chiranjivi,

 

Thanks for looking into this problem. 

 

With the Account Manager asset, the user isn't created at all (I get the required attribute error message for email).  I've turned the required attribute off for email, and the system displays the following errors:

 

Your account was not created. Ensure you have entered a username and password and try again.

  • preg_match(): Compilation failed: invalid range in character class at offset 151
  • preg_match(): Compilation failed: invalid range in character class at offset 104
  • "xxxxx@email.com" is not a valid value for attribute "email" [SYS0073]
  • "xxxxx@email.com" is not a valid value for attribute "email" [SYS0073]

I've tried the following email addresses:   name@email.com,  first.last@email.com, name@email.gsi.gov.uk (our work account).

 

I tried to create a new user asset and backend user asset in the admin interface, and it is also throwing the same errors as above.

 

Thanks,

Robin.


(Chiranjivi Upreti) #5

Ok re-reading the code, the issue was not due to the email generating the invalid regex. The regex used to validate the email address is actually static:

/^[a-zA-Z]+((['\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*\s+<([0-9a-zA-Z_\+\-&'\*\/=\?\^\{\}~]+(\.[0-9a-zA-Z_\+\-&'\*\/=\?\^\{\}~]+)*@(((?:[\da-zA-Z]|[\da-zA-Z]['\-\w]*[\da-zA-Z])\.)+[a-zA-Z]{2,7}))>$/

Based on the error message you are getting (invalid range in character class at offset 151, 104), its referring to literal '-' and '*' char respectively in the regex, which are required to be escaped when used inside character class ([] block). However they already are escaped and should not be throwing the error you are getting.

 

I am not able to replicate the issue in my local system using the that same function. Running this script with this regex works for me in my local system with PHP 5.4.40:

$regex = "/^[a-zA-Z]+((['\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*\s+<([0-9a-zA-Z_\+\-&'\*\/=\?\^\{\}~]+(\.[0-9a-zA-Z_\+\-&'\*\/=\?\^\{\}~]+)*@(((?:[\da-zA-Z]|[\da-zA-Z]['\-\w]*[\da-zA-Z])\.)+[a-zA-Z]{2,7}))>$/";
preg_match($regex, 'Someone <some.one@xyz.net>');

This regex failing basically means none of the email addresses in your Matrix system that uses this validation should be validating. Did you started getting this error after recent system upgrade?


(Robin Bilney) #6

Yes we did upgrade recently. What's the best way to fix this? 

 

Should I check the file to make sure that the regex has the literals escaped as you've got above and modify if not?  Or should we run the upgrade script again?

 

Thanks for your help.


(Robin Bilney) #7

I've edited the regex expression in the fudge/general/www.inc file to match what you have put above and it has stopped Matrix from throwing the preg_match() errors and I can now enter email address for users and register users using account manager asset.

 

However, the system still isn't sending emails. I've checked the mail error log and it has:

postfix/sendmail[28182]: fatal: Recipient addresses must be specified on the command line or via the -t option

In our External Tools Configuration, it has the path to sendmail binary and also -t in the arguments section.  Any idea why we are getting this error?

 

Thanks,

Robin


(Chiranjivi Upreti) #8

I've edited the regex expression in the fudge/general/www.inc file to match what you have put above and it has stopped Matrix from throwing the preg_match() errors and I can now enter email address for users and register users using account manager asset.

 

Aha! The issue you are having can be replicated in recent version of PCRE (>8.32). This has already been fixed in Squizmap #7322.

 

To fix this issue you will need to upgrade to Matrix version 5.1.12.2 / 5.2.4.0 at least.

 

Alternatively you can patch you system manually with the following changes:

diff --git a/fudge/general/www.inc b/fudge/general/www.inc
index 8a79fa1..b89fe29 100755
--- a/fudge/general/www.inc
+++ b/fudge/general/www.inc
@@ -112,10 +112,10 @@ function valid_email($e)
    
// dot character cannot be the first or last character in the local-part
    // and it cannot appear two or more times consecutively    
-    if (preg_match('/^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*\s+<(['.$local.']+(\.['.$local.']+)*@(((?:[\da-zA-Z]|[\da-zA-Z][\'-\w]*[\da-zA-Z])\.)+[a-zA-Z]{2,7}))>$/', $e)) {
+    if (preg_match('/^[a-zA-Z]+(([\'\,\.\- ][a-zA-Z ])?[a-zA-Z]*)*\s+<(['.$local.']+(\.['.$local.']+)*@(((?:[\da-zA-Z]|[\da-zA-Z][\'\-\w]*[\da-zA-Z])\.)+[a-zA-Z]{2,7}))>$/', $e)) {
     // matches email with display name, for example, 'Someone <some.one@squiz.net>'
     return TRUE;
- } else if (preg_match('/^(['.$local.']+(\.['.$local.']+)*@(((?:[\da-zA-Z]|[\da-zA-Z][\'-\w]*[\da-zA-Z])\.)+[a-zA-Z]{2,7}))$/', $e)) {
+ } else if (preg_match('/^(['.$local.']+(\.['.$local.']+)*@(((?:[\da-zA-Z]|[\da-zA-Z][\'\-\w]*[\da-zA-Z])\.)+[a-zA-Z]{2,7}))$/', $e)) {
     // matches normal email address
     return TRUE;
  } else {

The reason the email are still not being send is likely due to email validation still failing (the regex I provided you before was only one of the two parts of this fix).