Jump to content
adrian

Email New User

Recommended Posts

This seems to be a very versatile and hackable module, thank you for creating it :)

I've already created a version, which only emails the admin, when a new user is created (=registers on their own).

Now I'm tinkering with a version, which only emails the user manually, with the "Send email" feature in the user page.

If I want to block the automatic emailing on user creation, is it enough to add

if(!$this->page->process == 'ProcessUser') return;

in the sendNewUserEmail function before the other exiting conditions?

I though I'd ask and share the inspiration, before I even put the site online and can actually test the emailing functionality :)

My goal is to import a bunch of users from another CMS, send them the welcome email on creation, then disable adrian's original module and enable my two modified modules permanently.

Share this post


Link to post
Share on other sites

Hi Beluga - glad you are finding it useful, although I have to wonder if your use case for emailing the admin when a new user registers couldn't be better handled by a separate custom module - most of the code from this module is likely not relevant.

I think your tinkering regarding a manual only send email feature might be a useful option for this module. It could be a configurable option that adds a checkbox to the user page which could be checked or unchecked by default which determines whether the email is sent or not when registering a new user - would that work for you?

Share this post


Link to post
Share on other sites

I think your tinkering regarding a manual only send email feature might be a useful option for this module. It could be a configurable option that adds a checkbox to the user page which could be checked or unchecked by default which determines whether the email is sent or not when registering a new user - would that work for you?

It sure would work. Thanks for considering it.

Share this post


Link to post
Share on other sites

Ok, there is a new version with a new config setting: Automatic Email Send. This is checked by default, but if you uncheck this, then when creating new users the Send Email checkbox will be unchecked by default, so you will need to manually check each time to want to email a new user upon creation. This setting also works with users added via the API. If unchecked, they won't be sent an email, so you will need to use:

$newuser->sendEmail = true;

to have the email sent.

Hope that meets your needs and others also find it useful!

  • Like 2

Share this post


Link to post
Share on other sites

Ok, now I got to test it on an online site.

Some notes:

- if creating users with CSV import, the pwd is generated only, if left blank in the CSV. If pwd exists in CSV, it won't be overwritten by a generated one. I don't know, if this is intentional, so decided to mention

- users registered via FrontendUser module will not trigger emails!

Here is the source for the FrontendUser module in Bitbucket.

Share this post


Link to post
Share on other sites
- if creating users with CSV import, the pwd is generated only, if left blank in the CSV. If pwd exists in CSV, it won't be overwritten by a generated one. I don't know, if this is intentional, so decided to mention

This is intentional - if you want the automatically generated password to be used, make sure the password field is not populated.

- users registered via FrontendUser module will not trigger emails!

Not surprising - EmailNewUser is not autoload outside of the admin interface - see the instructions for using via the API where it mentions that you need to manually load it first. You could either change:

"autoload": "template=admin",

in the EmailNewUser.info.json to autoload : true or you would need to hack the FrontendUser module so that it loads this module with:

wire('modules')->get("EmailNewUser"); // call the module since it is not autoload on the front end

Perhaps you could request for pwFoo to add a check if this module is installed and if so, load it - others might find that useful too.

  • Like 1

Share this post


Link to post
Share on other sites

Thanks! Setting autoload to true actually didn't work, but it is simply enough for me to put this in my register.php:

$modules->get('EmailAdminNewUser');

Now I will get admin emails for users that have registered!

  • Like 2

Share this post


Link to post
Share on other sites

Dont really wortk for me with the FrontendUser Module 

<?php include('./_head.inc'); // include header markup 
$modules->get('EmailAdminNewUser'); // lade Modul um den Admin zu benachrichtigen 
?>
<div class='container paddingtop100'>
  <div class='row'>
            <div class='col-md-4'></div>
            <div class='col-md-4'><img class='img-responsive' src='../site/assets/files/1/pluco-logo.jpg'/></div>
            <div class='col-md-4'></div>
        </div> 
  </div>
<section  class="contain nav-link ">
    
<div  class="register weissbg">
<div class="small text-center" ><?=$page->body_m ?></div>
<div class='container '>
<div class='row'>
<?php 
$fu = $modules->get('FrontendUser');
// prepare login form (default parameters)
$fu->login();
// Default parameter
//$fu->login(array('username', 'password'));
    echo "<h4>Registrierte Nutzer hier anmelden</h4>";
// Additional LoginPersist and ProcessForgotPassword module integration (built-in)
$fu->login(array('username', 'password',  'forgot'));
// process login / form submit
$fu->process('../objekte/');
// output form
echo $fu->render();
 ?>
<?php 
    echo "<br /><h4>Nutzerregistrierung</h4>";

$u_vorname = $modules->get('InputfieldText');
$u_vorname->label = $this->_('Vorname*');
$u_vorname->attr('id+name', 'u_vorname');
$u_vorname->required = 1;
$u_vorname->fhSanitizer = 'text';
$nachname = $modules->get('InputfieldText');
$nachname->label = $this->_('Nachname*');
$nachname->attr('id+name', 'nachname');
$nachname->required = 1;
$nachname->fhSanitizer = 'text';
$unternehmen = $modules->get('InputfieldText');
$unternehmen->label = $this->_('Unternehmen*');
$unternehmen->attr('id+name', 'unternehmen');
$unternehmen->required = 1;
$unternehmen->fhSanitizer = 'text';
$strnr = $modules->get('InputfieldText');
$strnr->label = $this->_('Strasse / Hausnummer*');
$strnr->attr('id+name', 'strnr');
$strnr->required = 1;
$strnr->fhSanitizer = 'text';
$plz = $modules->get('InputfieldText');
$plz->label = $this->_('Plz / Ort*');
$plz->attr('id+name', 'plz');
$plz->required = 1;
$plz->fhSanitizer = 'text';
$tel = $modules->get('InputfieldText');
$tel->label = $this->_('Telefonnummer*');
$tel->attr('id+name', 'tel');
$tel->required = 1;
$tel->fhSanitizer = 'text';

$fu->addHookBefore('save', function($event) {
    $form = wire('fu')->form;
    $user = wire('fu')->userObj;
    $user->addRole('registered');
    if(!count($form->getErrors())) {

        wire('fu')->userObj->u_vorname = $form->fhValue('u_vorname', 'text');
        wire('fu')->userObj->u_nachname = $form->fhValue('nachname', 'text');
        wire('fu')->userObj->u_unternehmen = $form->fhValue('unternehmen', 'text');
        wire('fu')->userObj->u_hausnummer = $form->fhValue('strnr', 'text');
        wire('fu')->userObj->u_plzort = $form->fhValue('plz', 'text');
        wire('fu')->userObj->u_telefonnummer = $form->fhValue('tel', 'text');
 
    }
});
// Call hook after field is processed by PW form api
// prepare register form
$fu->register();
// Default parameter
//$fu->register(array('username', 'email', 'password'));
// Additional email pre-register validation plugin (built-in)
$fu->register(array('username',  $u_vorname, $nachname, $unternehmen , $strnr, $plz, $tel, 'email', 'password'));
// process register / form submit
$fu->process('../registrieren/aktivation/');
// output register form
echo $fu->render();
echo "<p class='small description'>* Gekennzeichnete Felder sind Pflichtangaben<br />Nach der Freischaltung erhalten Sie umgehend eine Bestätigungs-Email mit Ihren Login-Daten.</p>";
?>
</div>
</div>
</div>
</section>
  
<?php include('./_foot.inc'); // include footer markup ?>

whats the mistake here ? 

Share this post


Link to post
Share on other sites

@iNoize,

Looking at your code, you are loading: EmailAdminNewUser rather than EmailNewUser. So, you are not using this module at all, but rather a module written by @Beluga - https://processwire.com/talk/topic/9811-frontenduser-login-logout-and-register-users-members/?p=101533

So I am afraid you will need to ask him about it.

Share this post


Link to post
Share on other sites

Hi, I'm consistently getting the error: 

 No email was sent to the new user because of an unknown problem. Please try the 'Re-send Welcome Message' option.

I'm assuming this is a server configuration problem, does anyone have any idea how to go about rectifying/troubleshooting this?

EDIT: Really strange, if I hardcode the 'from' email address into line 141 instead of using the passed variable (which as far as I can see is exactly the same) it works correctly.

Share this post


Link to post
Share on other sites

Hi @ZGD and welcome to the forums!

Sorry you are having troubles with this module. It does sound like a very weird situation indeed.

Can you please confirm that the from email address is correctly filled out in the module config settings, like so:

post-985-0-10727300-1441374057_thumb.png

If it is, could you try an:

error_log($this->data['fromEmail']);

just after line 141 and see what it returns.

Share this post


Link to post
Share on other sites

Very strange indeed, I'd checked it multiple times, but copy pasting the email address back into the same input seems to have fixed it. I have no idea what happened there, but thanks for suggesting to check it once again.

I have one other question regarding using this in conjunction with Ryan's Import Pages from CSV module. I have a test CSV with 4 columns (title,displayname,email,roles) and 5 rows. I'm trying to import multiple users and have EmailNewUser auto-generate a password for each, it works successfully for the first user/row, but then I get the error "No email was sent to the new user because either their email address or password was not set." after that, I'm assuming because of line 137 (although I'm not sure if it's because of the email or password being blank? Has anyone successfully managed to do this?

EDIT: Seems if I include the 'pass' column, and use "" as the value for each row, it works!

  • Like 1

Share this post


Link to post
Share on other sites

Great - glad to hear you got everything working. 

I am super busy here at the moment and don't have time right now to see if there would be a simple way to remove the need for a blank "pass" column in the CSV field, but I don't think it matters so long as anyone attempting this knows it is required.

Share this post


Link to post
Share on other sites

Thanks adrian, the users have very restricted access to non-sensitive information for this one, it's more of a formality really. I will definitely be using ForcePasswordChange for future projects though, super easy to manage users through PW with these kinds of modules.

  • Like 1

Share this post


Link to post
Share on other sites

I changed my host to a dedicated server. I installed Postfix. Sending test email from module settings does not work.

It works (I receive email), if I replace the "wireMail(wire.." line with:

$mail = wireMail();
$mail->to('somemail@somesite.com')->from('myemail@site.com');
$mail->subject('Mail Subject');
$mail->body('Mail Body');
$mail->bodyHTML('<html><body><h1>Mail Body</h1></body></html>');
$mail->send();

How can I troubleshoot this? With Tracy debugger? :)

Share this post


Link to post
Share on other sites

Hi @Beluga,

Firstly, is it only the test send that isn't working, or do they also fail when adding a new user?

Well I don't think there should be a reason why the syntax you changed it to should work while the:

wireMail('user@domain.com', 'ryan@runs.pw', 'Mail Subject', 'Mail Body'); 

syntax won't.

I think the most likely problem is that I had an incorrect static call to a non-static method in there when doing the test send. Maybe your new server is failing on strict errors? I have fixed this in the latest version. Please let me know if that fixes it for you.

If it doesn't then you could play with Tracy like this and make sure they all return what is expected.

        // send test email if requested
        if (wire('input')->post->test) {
            bd(wire('user')->email, 'Admin User Email');
            bd($data['fromEmail'], 'From Email');
            bd($data['subject'], 'Subject'); // not really relevant, but may as well confirm its value
            bd(EmailNewUser::parseBody($data['body'], $data['fromEmail'], wire('user'), 'password'), 'Body'); // again, not really relevant
            wireMail(wire('user')->email, $data['fromEmail'], $data['subject'], self::parseBody($data['body'], $data['fromEmail'], wire('user'), 'password'));
        }
You will of course have to enable the Tracy debug bar for the backend.

Share this post


Link to post
Share on other sites

I use manual sending of the welcome email. I tested it and it does not work either. I used your bd() and the contents dumped look fine, my email is there etc.

I realized it is a general problem so I posted to the WireMail thread.

  • Like 1

Share this post


Link to post
Share on other sites
On 7/20/2015 at 4:28 PM, Beluga said:

Thanks! Setting autoload to true actually didn't work, but it is simply enough for me to put this in my register.php:


$modules->get('EmailAdminNewUser');

Now I will get admin emails for users that have registered!

Thanks for this @Beluga I had to use 

$modules->get('EmailNewUser');

in my register.php instead. But it works with the FrontendUser now. Very useful module @adrian!

  • Like 3

Share this post


Link to post
Share on other sites

I am also getting:

Session: No email was sent to the new user because of an unknown problem. Please try the 'Re-send Welcome Message' option.

PW 2.7.2

Share this post


Link to post
Share on other sites
1 hour ago, benbyf said:

I am also getting:

Session: No email was sent to the new user because of an unknown problem. Please try the 'Re-send Welcome Message' option.

PW 2.7.2

Are you using this with the frontend user module? Are you adding the user via the API or admin? Is the test send working ok?

Share this post


Link to post
Share on other sites

I didn't try the test as it wasnt obvious. I installed, added the settings, then went and created a user in the admin and got the error a couple of times (even when hard coding the email in the module as suggested above).

Share this post


Link to post
Share on other sites
9 minutes ago, benbyf said:

I didn't try the test as it wasnt obvious. I installed, added the settings, then went and created a user in the admin and got the error a couple of times (even when hard coding the email in the module as suggested above).

I am going to need more to go on here. I have been using this module on all my sites (on several different PW versions) since I created it. I don't suppose you could give me access to the server to take a look?

  • Like 1

Share this post


Link to post
Share on other sites

Really sorry but its a clients site not my own personal project. I cant seem to send out through wiremail() so that might be the issue. php mail() works fine.

Share this post


Link to post
Share on other sites
2 minutes ago, benbyf said:

Really sorry but its a clients site not my own personal project.

No problem - understood!

2 minutes ago, benbyf said:

I cant seem to send out through wiremail() so that might be the issue. php mail() works fine.

Do we agree then that it's not an issue with this module, but rather with the setup in your wireMail sending module?

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By Robin S
      Repeater Images
      Adds options to modify Repeater fields to make them convenient for "page-per-image" usage. Using a page-per-image approach allows for additional fields to be associated with each image, to record things such as photographer, date, license, links, etc.
      When Repeater Images is enabled for a Repeater field the module changes the appearance of the Repeater inputfield to be similar (but not identical) to an Images field. The collapsed view shows a thumbnail for each Repeater item, and items can be expanded for field editing.
      Screencast

      Installation
      Install the Repeater Images module.
      Setup
      Create an image field to use in the Repeater field. Recommended settings for the image field are "Maximum files allowed" set to 1 and "Formatted value" set to "Single item (null if empty)". Create a Repeater field. Add the image field to the Repeater. If you want additional fields in the Repeater create and add these also. Repeater Images configuration
      Tick the "Activate Repeater Images for this Repeater field" checkbox. In the "Image field within Repeater" dropdown select the single image field. You must save the Repeater field settings to see any newly added Image fields in the dropdown. Adjust the image thumbnail height if you want (unlike the core Images field there is no slider to change thumbnail height within Page Edit). Note: the depth option for Repeater fields is not compatible with the Repeater Images module.
      Image uploads feature
      There is a checkbox to activate image uploads. This feature allows users to quickly and easily add images to the Repeater Images field by uploading them to an adjacent "upload" field.
      To use this feature you must add the image field selected in the Repeater Images config to the template of the page containing the Repeater Images field - immediately above or below the Repeater Images field would be a good position.
      It's recommended to set the label for this field in template context to "Upload images" or similar, and set the visibility of the field to "Closed" so that it takes up less room when it's not being used. Note that when you drag images to a closed Images field it will automatically open. You don't need to worry about the "Maximum files allowed" setting because the Repeater Images module overrides this for the upload field.
      New Repeater items will be created from the images uploaded to the upload field when the page is saved. The user can add descriptions and tags to the images while they are still in the upload field and these will be retained in the Repeater items. Images are automatically deleted from the upload field when the page is saved.
      Tips
      The "Use accordion mode?" option in the Repeater field settings is useful for keeping the inputfield compact, with only one image item open for editing at a time. The "Repeater item labels" setting determines what is shown in the thumbnail overlay on hover. Example for an image field named "image": {image.basename} ({image.width}x{image.height})  
      https://github.com/Toutouwai/RepeaterImages
      https://modules.processwire.com/modules/repeater-images/
    • By EyeDentify
      Hello There Guys.

      I am in the process of getting into making my first modules for PW and i had a question for you PHP and PW gurus in here.

      I was wondering how i could use an external library, lets say TwitterOAuth in my PW module.
      Link to library
      https://twitteroauth.com/

      Would the code below be correct or how would i go about this:
      <?PHP namespace ProcessWire; /* load the TwitterOAuth library from my Module folder */ require "twitteroauth/autoload.php"; use Abraham\TwitterOAuth\TwitterOAuth; class EyeTwitter extends WireData,TwitterOAuth implements Module { /* vars */ protected $twConnection; /* extend parent TwitterOAuth contructor $connection = new TwitterOAuth(CONSUMER_KEY, CONSUMER_SECRET, $access_token, $access_token_secret); */ public function myTwitterConnection ($consumer_key, $consumer_secret, $access_token, $access_token_secret) { /* save the connection for use later */ $this->twConnection = TwitterOAuth::__construct($consumer_key, $consumer_secret, $access_token, $access_token_secret); } } ?> Am i on the right trail here or i am barking up the wrong tree?
      I don´t need a complete solution, i just wonder if i am including the external library the right way.
      If not, then give me a few hint´s and i will figure it out.

      Thanks a bunch.

      /EyeDentify
    • By dimitrios
      Hello,
      this module can publish content of a Processwire page on a Facebook page, triggered by saving the Processwire page.
      To set it up, configure the module with a Facebook app ID, secret and a Page ID. Following is additional configuration on Facebook for developers:
      Minimum Required Facebook App configuration:
      on Settings -> Basics, provide the App Domains, provide the Site URL, on Settings -> Advanced, set the API version (has been tested up to v3.3), add Product: Facebook Login, on Facebook Login -> Settings, set Client OAuth Login: Yes, set Web OAuth Login: Yes, set Enforce HTTPS: Yes, add "http://www.example.com/processwire/page/" to field Valid OAuth Redirect URIs. This module is configurable as follows:
      Templates: posts can take place only for pages with the defined templates. On/Off switch: specify a checkbox field that will not allow the post if checked. Specify a message and/or an image for the post.
      Usage
      edit the desired PW page and save; it will post right after the initial Facebook log in and permission granting. After that, an access token is kept.
       
      Download
      PW module directory: http://modules.processwire.com/modules/auto-fb-post/ Github: https://github.com/kastrind/AutoFbPost   Note: Facebook SDK for PHP is utilized.


    • By kongondo
      FieldtypeRuntimeMarkup and InputfieldRuntimeMarkup
       
      Modules Directory: http://modules.processwire.com/modules/fieldtype-runtime-markup/
      GitHub: https://github.com/kongondo/FieldtypeRuntimeMarkup
      As of 11 May 2019 ProcessWire versions earlier than 3.x are not supported
      This module allows for custom markup to be dynamically (PHP) generated and output within a page's edit screen (in Admin).
       
      The value for the fieldtype is generated at runtime. No data is saved in the database. The accompanying InputfieldRuntimeMarkup is only used to render/display the markup in the page edit screen.
       
      The field's value is accessible from the ProcessWire API in the frontend like any other field, i.e. it has access to $page and $pages.
       
      The module was commissioned/sponsored by @Valan. Although there's certainly other ways to achieve what this module does, it offers a dynamic and flexible alternative to generating your own markup in a page's edit screen whilst also allowing access to that markup in the frontend. Thanks Valan!
       
      Warning/Consideration
      Although access to ProcessWire's Fields' admin pages is only available to Superusers, this Fieldtype will evaluate and run the custom PHP Code entered and saved in the field's settings (Details tab). Utmost care should therefore be taken in making sure your code does not perform any CRUD operations!! (unless of course that's intentional) The value for this fieldtype is generated at runtime and thus no data is stored in the database. This means that you cannot directly query a RuntimeMarkup field from $pages->find(). Usage and API
       
      Backend
      Enter your custom PHP snippet in the Details tab of your field (it is RECOMMENDED though that you use wireRenderFile() instead. See example below). Your code can be as simple or as complicated as you want as long as in the end you return a value that is not an array or an object or anything other than a string/integer.
       
      FieldtypeRuntimeMarkup has access to $page (the current page being edited/viewed) and $pages. 
       
      A very simple example.
      return 'Hello'; Simple example.
      return $page->title; Simple example with markup.
      return '<h2>' . $page->title . '</h2>'; Another simple example with markup.
      $out = '<h1>hello '; $out .= $page->title; $out .= '</h1>'; return $out; A more advanced example.
      $p = $pages->get('/about-us/')->child('sort=random'); return '<p>' . $p->title . '</p>'; An even more complex example.
      $str =''; if($page->name == 'about-us') { $p = $page->children->last(); $str = "<h2><a href='{$p->url}'>{$p->title}</a></h2>"; } else { $str = "<h2><a href='{$page->url}'>{$page->title}</a></h2>"; } return $str; Rather than type your code directly in the Details tab of the field, it is highly recommended that you placed all your code in an external file and call that file using the core wireRenderFile() method. Taking this approach means you will be able to edit your code in your favourite text editor. It also means you will be able to type more text without having to scroll. Editing the file is also easier than editing the field. To use this approach, simply do:
      return wireRenderFile('name-of-file');// file will be in /site/templates/ If using ProcessWire 3.x, you will need to use namespace as follows:
      return ProcessWire\wireRenderFile('name-of-file'); How to access the value of RuntimeMarkup in the frontend (our field is called 'runtime_markup')
       
      Access the field on the current page (just like any other field)
      echo $page->runtime_markup; Access the field on another page
      echo $pages->get('/about-us/')->runtime_markup; Screenshots
       
      Backend
       

       

       
      Frontend
       

×
×
  • Create New...