Jump to content

Email New User


adrian

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.

Link to comment
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?

Link to comment
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.

Link to comment
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
Link to comment
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.

Link to comment
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
Link to comment
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
Link to comment
Share on other sites

  • 1 month later...

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 ? 

Link to comment
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.

Link to comment
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.

Link to comment
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.

Link to comment
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
Link to comment
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.

Link to comment
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
Link to comment
Share on other sites

  • 6 months later...

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? :)

Link to comment
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.
Link to comment
Share on other sites

  • 2 months later...
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
Link to comment
Share on other sites

  • 2 months later...
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?

Link to comment
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
Link to comment
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?

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
×
×
  • Create New...