adrian

Email New User

Recommended Posts

I catch emails with Tracy´s mail interceptor, but no email is there. 

Share this post


Link to post
Share on other sites
Just now, jmartsch said:

Yes, I removed that line, but email is still not being sent.

I even set autoload to true in the settings file, but that changes nothing.

Don't know why the email is not sent

Is this site online? Can I take a look?

Share this post


Link to post
Share on other sites

I just tested with Mail Interceptor and it's catching the email just fine. Would you mind debugging the sendNewUserEmail() function - see if it's being called at all and where it is failing?

Share this post


Link to post
Share on other sites

Hey Adrian, I spotted another bug.

If you go to the modules settings and check the "Generate Password" option, then after saving an error occurs: "Session: You need to have digits and at least one of the letter options checked."

Share this post


Link to post
Share on other sites
5 minutes ago, jmartsch said:

Hey Adrian, I spotted another bug.

If you go to the modules settings and check the "Generate Password" option, then after saving an error occurs: "Session: You need to have digits and at least one of the letter options checked."

Sorry about that - I wasn't seeing that because I had an older, updated install that already had those options stored in the settings database.

New version just committed fixes it.

Thanks again!

  • Like 2

Share this post


Link to post
Share on other sites

Hi Adrian, I have a question :) 

I implemented login via link base on @Ivan Gretsky's code snippet: https://processwire.com/talk/topic/13708-login-with-a-link-is-it-called-magic-link/?do=findComment&comment=155465

I'm also using your module so that the site manager creating the users in the admin does not have to send the very first email to the user manually. The module sends the email successfully but I have a two issues:

  • While http://example.com/?user={id}&token={login_token} is turned into the proper "link", hardcoding the protocol+domain is not a good idea and {adminUrl} is not what I need.
  • I also implemented a simple form asking for an email only. When submitted,  the login token is regenerated for the user (associated with that email) and an email is sent with the new login link in it. It would be great to be able to base these two emails (mail sent by this module and mail sent by my form) on the same template, meaning they should be identical without me implementing them twice.

My function to send the new link via email is dead simple:

<?php
function site_email_user_login_info($login_user) {
    createLoginToken($login_user);
    $login_link = createLoginLink($login_user);
    $mail = wireMail();
    $mail->to($login_user->email);
    $mail->from('contact@example.com');
    $mail->subject('How to login...');
    $mail->bodyHTML("<html><body>
                        <h2>Some dummy header</h2>
                        <p>Some placeholder text. Blah-blah. Please click to login:</p>
                        <a href='{$login_link}'>{$login_link}</a>
                     </body></html>");
    $mail->send();
}

It is bodyHTML and the module's Email Massage which should be populated from the same source. Could you please give me some guidance on how to achieve this? Is it possible?

 

Share this post


Link to post
Share on other sites

Hi @szabesz - if I understand correctly, I think you could make use of this module instead of your custom site_email_user_login_info() function.

Via the API you can use:

$u->sendEmail = true;

If you need to adjust the body of the email (both via admin and frontent/API), you can hook into: EmailNewUser:: parseBody - you could add your own logic for dynamically building the http://example.com/?user={id}&token={login_token} link without hardcoding anything.

https://processwire.com/talk/topic/7051-email-new-user/?do=findComment&comment=136252

Let me know how you go.

  • Like 1

Share this post


Link to post
Share on other sites
3 hours ago, adrian said:

EmailNewUser:: parseBody

Thank you Adrian, this is what I need. I've long forgotten about it even though I did read your post.

I've just refactored my code to take advantage of it and everything works as expected, great module as always!

As for $u->sendEmail = true; I do not need it because my frontend form is not for creating new users but for sending an email to existing users. Why sending the same email? Because already registered users might have long forgotten how to login to the system so I want to send the same instructions no matter what. I will probably introduce a slight difference based on some simple logic but most part of the email body will be the same. For this reason I use the hook to completely overwrite $htmlBody which I find easier to implement than using str_replace and such to change something created in the RTE.

  • Like 1

Share this post


Link to post
Share on other sites

Hi @adrian,

My first time using this lovely module. A question and a couple of requests...

When editing/saving a user in admin, under what circumstances is an email sent if the "Automatic Email Send" option is checked? For existing users (who may have already been sent their welcome message) will an email be sent if nothing is changed but the user just saved? Silly me, I was trying to work it out from the code rather than just trying it out. I see now that the interface changes to "Re-send welcome message" after the first user save.

Request 1: It would be cool if there was an option in the module config to select key fields in the user template, where if any of those fields have changed the user is automatically sent an email. The obvious fields to trigger this would be "name" and "pass", but it would be nice to include custom fields too because in my case users log in with their email address. If other fields are changed no email would be sent. As I type this another thought occurs to me - maybe there could be different email templates for "new user" (password old value is blank) versus "modified user" (key field has changed)?

Request 2: How about a module config option for not showing the "Send welcome message" checkbox and the "Email message" CKEditor field in Edit User? In my scenario there are several different roles with different user-admin privileges. I'd rather take the decisions out of their hands whether or not to send an email and what the message will be.

  • Like 1

Share this post


Link to post
Share on other sites

Hi @Robin S

All the "Automatic Email Send" option does is check the "Send welcome message" option when creating a new user. It doesn't have any impact on existing users, but there is an option to "Resend Welcome Message" to an existing user. This will re-generate a new password if that option is selected.

As for your requests, unfortunately I just don't have time at the moment as those look relatively substantial, but they sound useful. I think "2" especially sounds like a good idea. I am not sure about "1" - it sounds like it might be beyond the scope of "Email New User", but I am happy to be convinced that it's a worthwhile addition.

There's realistically no chance of me getting to this until late May, but of course PRs are always greatly appreciated :) Sorry I can't help out in a reasonable timeframe on this one!

 

  • Like 1

Share this post


Link to post
Share on other sites

Thanks @adrian, no worries. The needs of my current project are fairly specific/unique so I'm not sure yet whether I'll modify the Email New User module or make a new custom module. I'm sure your module will be a big help in either case, and if I do make some additions to Email New User that could be useful to others I'll certainly share them here.

  • Like 1

Share this post


Link to post
Share on other sites

Hey @Robin S - I think Request 2 would be pretty quick to implement, so might take a look at that when I am procrastinating from work.

  • Like 1

Share this post


Link to post
Share on other sites
6 hours ago, Robin S said:

Request 1: It would be cool if there was an option in the module config to select key fields in the user template, where if any of those fields have changed the user is automatically sent an email.

Just chiming in to point out that this sounds like something that might be better solved by the Field Change Notifier module. I'm not sure what the state of said module is, and it doesn't currently seem to support selecting notified user based on the page being edited either, but perhaps it would be easier to adapt to this need? :)

  • Like 2

Share this post


Link to post
Share on other sites

Hi @adrian, just a heads up:

I was again experiencing this issue that you raised in the PW issues repo a while ago: https://github.com/processwire/processwire-issues/issues/432

It was a bit puzzling but I traced it back to the Email New User module which I was testing out. Due to this commit the module is undoing the fix that was applied in the PW core.

Share this post


Link to post
Share on other sites

Hi @Robin S - sorry about that. I can try to take a look tomorrow, but maybe in the meantime @Torsten Baldes could also see if there is an alternative to that commit of his that fixed the password issue, but not have the side-effect of breaking user saving?

Share this post


Link to post
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


  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By BitPoet
      As threatened in the Pub sub forum in the "What are you currently building?" thread, I've toyed around with Collabora CODE and built file editing capabilities for office documents (Libre-/OpenOffice formats and MS Office as well as a few really old file types) into a PW module.
      If you are running OwnCloud or NextCloud, you'll perhaps be familiar with the Collabora app for this purpose.
      LoolEditor
      Edit office files directly in ProcessWire
      Edit your docx, odt, pptx, xlsx or whatever office files you have stored in your file fields directly from ProcessWire's page editor. Upload, click the edit icon, make your changes and save. Can be enabled per field, even in template context.
      Currently supports opening and saving of office documents. Locking functionality is in development.
      See the README on GitHub for installation instructions. You should be reasonably experienced with configuring HTTPS and running docker images to get things set up quickly.
      Pull requests are welcome!
      Here is a short demonstration:

    • By Robin S
      An Images field allows you to:
      Rename images by clicking the filename in the edit panel or in list view. Replace images, keeping metadata and filename (when possible) by dropping a new image on the thumbnail in the edit panel. Introduced here. But neither of these things is possible in File fields, which prompted this module. The way that files are renamed or replaced in this module is not as slick as in the Images field but it gets the job done. The most time-consuming part was dealing with the UI differences of the core admin themes. @tpr, gives me even more respect for the work that must go into AdminOnSteroids.
      Most of the code to support the rename/replace features is already present in InputfieldFile - there is just no UI for it currently. So hopefully that means these features will be offered in the core soon and this module can become obsolete.
       
      Files Rename Replace
      Allows files to be renamed or replaced in Page Edit.

      Usage
      Install the Files Rename Replace module.
      If you want to limit the module to certain roles only, select the roles in the module config. If no roles are selected then any role may rename/replace files.
      In Page Edit, click "Rename/Replace" for a file...
      Rename
      Use the text input to edit the existing name (excluding file extension).
      Replace
      Use the "Replace with" select to choose a replacement file from the same field. On page save the file will be replaced with the file you selected. Metadata (description, tags) will be retained, and the filename also if the file extensions are the same.
      Tip: newly uploaded files will appear in the "Replace with" select after the page has been saved.
       
      https://github.com/Toutouwai/FilesRenameReplace
      http://modules.processwire.com/modules/files-rename-replace/
    • By d'Hinnisdaël
      So I decided to wade into module development and created a wrapper module around ImageOptim, a service that compresses and optimizes images in the cloud. ImageOptim currently handles JPG, PNG and GIF files and, depending on the settings you use, shaves off between 15% and 60% in filesize. Great for bandwidth and great for users, especially on mobile.
      This module handles the part of uploading images to ImageOptim via their official API, downloading the optimized version and storing it alongside the original image.
       

       
      Download & Info
      GitHub / Module directory / Readme / Usage
       
      Why ImageOptim?
      There are other image optimization services out there, some of them free, that have outstanding ProcessWire modules. A few things make ImageOptim the best tool for most of my customers: It's not free, i.e. it will probably be around for a while and offers support. However, it's cheaper than some of the bigger competitors like Cloudinary. And it does PNG compression better than any of the free services out there, especially those with alpha channels.
       
      Installation
      Install the module like any other ProcessWire module, by either copying the folder into your modules folder or installing it via the admin. See above for downloads links on GitHub and in the module directory.
       
      Requirements
      To be able to upload images to the service, allow_url_fopen must be set on the server. The module will abort installation if that's not the case.
      I have only tested the module on ProcessWire 3.x installations. I don't see why it shouldn't work in 2.x, if anyone wants to try it out and report back.
       
      ImageOptim account
      To compress images, you first need to sign up for an ImageOptim account. They offer free trials to try the service.
       
      Usage (manual optimization)
      Images can be optimized by calling the optimize() method on any image. You can pass an options array to set ImageOptim API parameters.
      $image->size(800,600)->optimize()->url $image->optimize(['quality' => 'low', 'dpr' => 2]) // Set quality to low and enable hi-dpi mode
      Automatic optimization
      The module also has an automatic mode that optimizes all image variations after resizing. This is the recommended way to use this module since it leaves the original image uncompressed, but optimizes all derivative images.
      $image->size(800,600)->url // nothing to do here; image is optimized automatically
      To change compression setting for single images, you can pass an options array along with the standard ImageResizer options. Passing false disables optimization.
      $image->size(800, 600, ['optimize' => 'medium']) $image->size(800, 600, ['optimize' => ['quality' => 'low', 'dpr' => 2]]) $image->size(800, 600, ['optimize' => false])
      For detailed usage instructions and all API parameters, see the usage instructions on GitHub.
       
      Filenames
      Optimized images will be suffixed, e.g. image.jpg becomes image.optim.jpg. You can configure the suffix in the module settings.
       
      Roadmap
      Asynchronous processing. Not really high on the list. Image variations need to be created anyway, so waiting a few seconds longer on first load is preferable to adding complexity to achieve async optimization. Optimize image variations created by other modules. CroppableImage comes to mind. I don't use any of these, so if somebody wants to help out and submit a pull request — all for it! Add a dedicated page in the setup menu with a dashboard and detailed statistics. ImageOptim's API is very barebones for now, so not sure if that's feasible or even necessary.
      Stability
      I've been using this module on production sites for some time now, without hiccups. If you do notice oddities, feel free to comment here or investigate and submit PRs.
    • By daniels
      General
      This is a lightweight alternative to other newsletter & newsletter-subscription modules.
      It can update / create a subscriber in a list in Mailchimp with MailChimp API 3.0. It does not provide any forms or validation, so you can feel free to use your own. To protect your users, it does not save any user data in logs or sends them to an admin.
      This module fits your needs if you...
      ...use Mailchimp as your newsletter / email-automation tool ...want to let users subscribe to your newsletter on your website ...want to use your own form, validation and messages (with or without the wire forms) ...don't want any personal user data saved in any way in your ProcessWire environment (cf. EU data regulation terms) ...like to subscribe users to different lists ...like the Mailchimp UI for creating / sending / reviewing email campaigns You can find it here: https://github.com/danielstieber/SubscribeToMailchimp
      Let me know what you think and if I should add it to the Modules Directory.
      Setup
      Log into your Mailchimp account and go to  Profile > Extras > API Keys. If you don't have an API Key, create a new one. Copy your API Key and paste it in the module settings (Processwire > Modules > Site > SubscribeToMailchimp). Back in Mailchimp, go to the list, where you want your new subscribers. Go to Settings > List name and defaults. Copy the List ID an paste it in to the module settings.
      Usage
      To use the module, you need to load it into your template:
      $mc = $modules->get("SubscribeToMailchimp"); Now you can pass an email address to the module and it will try to edit (if the user exists) or create a new subscriber in your list.
      $mc->subscribe('john.doe@example.com'); You can also pass a data array, to add additional info.
      $mc->subscribe('john.doe@example.com', ['FNAME' => 'John', 'LNAME' => 'Doe']); You can even choose an alternative list, if you don't want this subscriber in your default list.
      $mc->subscribe('john.doe@example.com', ['FNAME' => 'John', 'LNAME' => 'Doe'], 'abcdef1356'); // Subscribe to List ID abcdef1356  
      Important Notes
      This module does not do any data validation. Use a sever-sided validation like Valitron Make sure that you have set up your fields in your Mailchimp list. You can do it at Settings > List fields and *|MERGE|* tags Example
      Example usage after a form is submitted on your page:
      // ... validation of form data $mc = $modules->get("SubscribeToMailchimp"); $email = $input->post->email; $subscriber = [ 'FNAME' => $input->post->firstname, 'LNAME' => $input->post->lastname, ]; $mc->subscribe($email, $subscriber);  
      Troubleshooting
      In case of trouble check your ProcessWire warning logs.
      I can't see the subscriber in the list
      If you have enabled double opt-in (it is enabled by default) you will not see the subscriber, until he confirmed the subscription in the email sent by Mailchimp
      I get an error in my ProccessWire warning logs
      Check if you have the right List ID and API Key. Check if you pass fields, that exist in your list. Check if you pass a valid email address. Go to Mailchimps Error Glossary for more Information
      How To Install
      Download the zip file at Github or clone directly the repo into your site/modules If you downloaded the zip file, extract it in your sites/modules directory. You might have to change the folders name to 'SubscribeToMailchimp'. Goto the modules admin page, click on refresh and install it  
    • By PWaddict
      Module for hiding pages for non-superusers.
      Download
      HidePages
      Requirements
      ProcessWire 3.x Changelog
      1.0.1 (31 March 2018)
      Module renamed to prevent confusion 1.0.0 (30 March 2018)
      Initial release