Jump to content

Piping emails to PW from cPanel


MarkE
 Share

Recommended Posts

I have been using ProcessEmailToPage for quite a while (heavily modified) but realise that it is not really supported plus it is rather OTT for my needs. I was looking at doing a much simpler script.

The idea is this - to pipe emails bvia cPanel's 'Default address' facility and then use the script to route them appropriately in PW. This has the huge advantage that it is not necessary to define the email addresses in cPanel and then set up a separate handler for each one in PW. The piping part works fine, and so does the email parsing as far as I can tell. However, I am having difficulty accessing the PW API. I read somewhere (I forget where) that it should be possible to place the script in site/templates/ with the ProcessWire namespace (and maybe include ./index.php ?) but I can't get any of that to work. The 'include' works OK, in that it does not break the script, but adding anything like wire() or 'new Page()' causes the script to fail.

Grateful for any suggestions!

Link to comment
Share on other sites

Inside site/templates, it would have to be include('../../index.php'), though you should be able to place the script anywhere outside the PW directory as long as you specify the correct path to the index.php that lives in PW's root directory. You'll have to make sure, of course, that the user under which cPanel runs has read access to the PW directories. Since php-cgi und php-cli sometimes use different php.ini files (depending on your OS), this may also be worth checking. Otherwise, if you're including the correct index.php and have the namespace set to ProcessWire, wire() and 'new Page()' will work.

  • Like 1
Link to comment
Share on other sites

9 hours ago, BitPoet said:

it would have to be include('../../index.php')

Thanks @BitPoet. Doh. You are right, of course, but that crashed the script. I have found what seems to be a little-known fact (certainly not turned up by my researches or by AI): if the piped script (or anything it includes or calls) has CRLF line separators, it will crash. I found a few files in the wire directory that had CRLF (not sure if this was caused by my system or if it is in the PW master). Once I changed these to LF, the script ran with include('../../index.php').

However, attempting to use the API then caused the script to crash - even something really simple like $mailReceivedPage = new Page(); As far as I can see, all the files are now LF. It's really difficult to debug as the only error message I can get is the delivery report, which says:

Child process of cagefs_virtual_address_pipe transport returned 255 (could mean shell command ended by signal 127 (Unknown signal 127)) from command: /bin/cagefs_enter

There's no easy way of telling exactly what crashed it. Any ideas on debugging this?

I am thinking of making a module as an alternative (push vs pull) version of ProcessEmailToPage (if I ever get this working). I will need to remember to warn users that all files must use LF!

Link to comment
Share on other sites

You can enable error logging for php-cli by setting error_log in /etc/php/cli/php.ini to something like "/var/log/php_errors.log".

If you have dos2unix on your system, you can recursively convert all files to proper LF line endings from within your PW directory.

find . -type f -name '*.php' -exec dos2unix {}
find . -type f -name '*.module' -exec dos2unix {}

 

  • Like 1
Link to comment
Share on other sites

Well, I haven't managed to 

19 minutes ago, BitPoet said:

enable error logging for php-cli

yet, but I ran the script from the command line and got "Call to undefined function ProcessWire\wire() in /home/xxx/public_html/site/templates/emailpipe.php:4", so it doesn't look like the API is enabled.

Script was

#!/usr/local/bin/php -q
<?php namespace ProcessWire;
include_once('../../index.php');
wire()->log->save('debug', 'emailpipe.php started');

 

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...