Jump to content
Lance O.

New User Welcome Message?

Recommended Posts

Does ProcessWire have include the ability to automatically send a welcome message to new users when their account is created? I'd like to send new users their login information, as well as some helpful links related to ProcessWire and their project. Ideally, I'd like to be able to edit the message.

Currently, I have the following set up in TextExpander. The capitalized words are changed using TextExpander's fill-in functionality.

Dear EMAIL,

Your new site has been successfully set up at:
http://DOMAIN/

You'll use ProcessWire to manage your site's content. You can log into your administrator account with the following information:

http://DOMAIN/processwire/
Username: USERNAME
Password: PASSWORD (case-sensitive)

Need to reset your password? Click on the 'Forgot your password?' link on the login page:
http://DOMAIN/processwire/

Learn how to create a strong and secure password:
http://www.google.com/goodtoknow/online-safety/passwords/

What makes ProcessWire so great? Learn about the set of features designed to make working with your content easy and enjoyable:
http://processwire.com/

Find out what makes ProcessWire unique from other content management systems:
http://processwire.com/about/what/

We hope you enjoy your new site!
 

Share this post


Link to post
Share on other sites

There's no built-in feature for this as far as I know, but something like this could be turned into a module with relative ease. Since users are essentially pages, your module could hook into saveReady() method of pages and do it's magic (such as sending an email using user credentials, essentially info taken from that page) to this user.

Password field is one I'm not very familiar with and thus I can't really say for sure if you'd be able to use it's actual value in this way. You may have to add another hook just to get that. Another option would be to avoid sending passwords and just instruct user to get a new password with "forgot your password" feature -- this is what many sites already do.

Anyway, in init() of your new module you'd add a hook:

$this->pages->addHook('saveReady', $this, 'sendEmail');

.. and that sendEmail method could look something like this, though probably you'd want to add some checks etc. (does email exists and so on):

public function sendEmail(HookEvent $event) {
    $page = $event->arguments[0];
    if ($page->template != "user") return; // stop here if this isn't a new user
    $message = "your message goes here.. or you could specify it in module settings. Hello {$page->name}!";
    mail($page->email, "welcome, {$page->name}!", $body);
}

You'll find plenty of examples on creating modules around the forum. I hope this helps you get started!

Edit: moved hook to "saveReady" instead of "saved."

Edited by teppo
  • Like 2

Share this post


Link to post
Share on other sites

I think you might get access to the password value if you hook before the page is saved, but I don't have time to give an example just now (Soma or someone else with fast typing fingers will doubtless be here soon with an example).

  • Like 1

Share this post


Link to post
Share on other sites

Actually, now that Pete mentioned it (kind of), it might be better to add that hook to saveReady instead of saved. You might have access to password in plain text at that point, but you'd still be (nearly) sure that page will get saved. When hooking to save, there's always the possibility that page won't get saved after all, and in that case it'd be awfully early to send that email :)

I'd still strongly suggest not sending passwords in plain text over unsecure mail protocol. That's why instruction to use "forgot your password?" feature is IMHO better choice.

  • Like 2

Share this post


Link to post
Share on other sites

Excellent advice. Looks like I will be developing my first ProcessWire Module!

  • Like 2

Share this post


Link to post
Share on other sites

Excellent advice. Looks like I will be developing my first ProcessWire Module!

Hey Lance, any news on this? :)

Share this post


Link to post
Share on other sites

There's no built-in feature for this as far as I know, but something like this could be turned into a module with relative ease. Since users are essentially pages, your module could hook into saveReady() method of pages and do it's magic (such as sending an email using user credentials, essentially info taken from that page) to this user.

Password field is one I'm not very familiar with and thus I can't really say for sure if you'd be able to use it's actual value in this way. You may have to add another hook just to get that. Another option would be to avoid sending passwords and just instruct user to get a new password with "forgot your password" feature -- this is what many sites already do.

Anyway, in init() of your new module you'd add a hook:

$this->pages->addHook('saveReady', $this, 'sendEmail');

.. and that sendEmail method could look something like this, though probably you'd want to add some checks etc. (does email exists and so on):

public function sendEmail(HookEvent $event) {
    $page = $event->arguments[0];
    if ($page->template != "user") return; // stop here if this isn't a new user
    $message = "your message goes here.. or you could specify it in module settings. Hello {$page->name}!";
    mail($page->email, "welcome, {$page->name}!", $body);
}

You'll find plenty of examples on creating modules around the forum. I hope this helps you get started!

Edit: moved hook to "saveReady" instead of "saved."

@teppo Thanks a lot for this example! I'm getting into learning hooks and this kind of examples are a lifesaver!!

I think that you missed an "@" before the mail function. Also, shouldn't this mail fire only when a new user is created? If new user ... fire the email. How would this be translated into code here?

Share this post


Link to post
Share on other sites

Let me elaborate a little bit more: I've been trying to pull this module off, and I haven't found the correct way to hook it. If I'm not mistaken, hooking into 'saveReady' in this case will trigger after saving AND editing the user. So In this case, it should trigger when the user page is Published (a.k.a the user is live and should be welcomed! :rolleyes: ). Looking into the hooks' list, I haven't found said hook or similar. So, I must be missing something, right?

Note that i've tried to hook after 'added' as well, and in this case it triggers after the name is set (and the page is first saved), so the user still hasn't filled his email to begin with.

<?php


class EmailNewUser extends WireData implements Module {

	/**
	 * getModuleInfo is a module required by all modules to tell ProcessWire about them
	 *
	 * @return array
	 *
	 */
	public static function getModuleInfo() {

		return array(

			// The module'ss title, typically a little more descriptive than the class name
			'title' => 'Email New Users', 

			// version: major, minor, revision, i.e. 100 = 1.0.0
			'version' => 101, 

			// summary is brief description of what this module is
			'summary' => 'An example to email New users',
			
			// Optional URL to more information about the module
			'href' => '',

			// singular=true: indicates that only one instance of the module is allowed.
			// This is usually what you want for modules that attach hooks. 
			'singular' => true, 

			// autoload=true: indicates the module should be started with ProcessWire.
			// This is necessary for any modules that attach runtime hooks, otherwise those
			// hooks won't get attached unless some other code calls the module on it's own.
			// Note that autoload modules are almost always also 'singular' (seen above).
			'autoload' => true, 
			);
	}

	/**
	 * Initialize the module
	 *
	 * ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called
	 * when ProcessWire's API is ready. As a result, this is a good place to attach hooks. 
	 *
	 */
	public function init() {

		
		$this->pages->addHookAfter('added', $this, 'sendEmail');

		

	}

	public function sendEmail(HookEvent $event) {
   		$page = $event->arguments[0];
    	if ($page->template != "user") return; // stop here if this isn't a new user
    	$body = "your message goes here.. or you could specify it in module settings. Hello {$page->name}!";
    	$this->message("Hello World! You created {$page->email}."); 
    	@mail($page->email, "welcome, {$page->name}!", $body, "From:xxxx@xxxx.com");
	}
	
}

Share this post


Link to post
Share on other sites

@landitus: you're right in that using the code I posted earlier message would get sent every time user is saved, which probably isn't correct behavior. One way to achieve what you're describing here would be by simply adding a check for changed status (published). You might want to take a look at Process Changelog for some sample code.

"@" character was missing by purpose; in PHP adding @ before function such as mail() suppresses errors. If you're relying on these emails getting sent, this makes very little sense, as it just tells PHP that "if this fails, no worries, just keep going as if nothing happened!" :)

  • Like 2

Share this post


Link to post
Share on other sites

Good to now! 

I was able to pull this off like this for now. Thanks a lot for your input! Maybe a config page will be better for a public module, off course.

<?php

class EmailNewUser extends WireData implements Module {

	/**
	 * getModuleInfo is a module required by all modules to tell ProcessWire about them
	 *
	 * @return array
	 *
	 */
	public static function getModuleInfo() {

		return array(

			// The module's title, typically a little more descriptive than the class name
			'title' => 'Email New Users', 

			// version: major, minor, revision, i.e. 100 = 1.0.0
			'version' => 101, 

			// summary is brief description of what this module is
			'summary' => 'Send New users a welcome email',
			
			// Optional URL to more information about the module
			'href' => '',

			// singular=true: indicates that only one instance of the module is allowed.
			// This is usually what you want for modules that attach hooks. 
			'singular' => true, 

			// autoload=true: indicates the module should be started with ProcessWire.
			// This is necessary for any modules that attach runtime hooks, otherwise those
			// hooks won't get attached unless some other code calls the module on it's own.
			// Note that autoload modules are almost always also 'singular' (seen above).
			'autoload' => true, 
			);
	}

	/**
	 * Initialize the module
	 *
	 * ProcessWire calls this when the module is loaded. For 'autoload' modules, this will be called
	 * when ProcessWire's API is ready. As a result, this is a good place to attach hooks. 
	 *
	 */
	public function init() {
		$this->pages->addHook('saveReady', $this, 'sendEmail');
	}

	public function sendEmail(HookEvent $event) {
   		$page = $event->arguments[0];
    	
    	if ($page->template != "user") return; // stop here if this isn't a User
    	
    	// Only send an email if the User page is published (A new User goes live)
    	if($page->isChanged('status') && !$page->is(Page::statusUnpublished)) {
    		$body = "Welcome {$page->name}!";
    		$this->message("Welcome {$page->name}! A welcome email has been sent to {$page->email}."); 
    		@mail($page->email, "welcome, {$page->name}!", $body, "From:xxxxx@xxxxx.com");
    	}
    	
	}

}

  • Like 6

Share this post


Link to post
Share on other sites

Just wanted to note here in this post that I've built a configurable module for this and also included optional support for automatically generating the password for the new user. You can read more about it here: https://processwire.com/talk/topic/7051-email-new-user/

Also, there was some discussion above about how to get the entered password in plain text, but I don't think anyone actually came up with a working solution. I found that you can hook on InputfieldPassword::processInput and then you can get the plain text password with $event->object->value

  • Like 5

Share this post


Link to post
Share on other sites

This is great news Adrian! Can't wait to try it! 

Great - let me know how it goes for you.

Thanks for the inspiration for putting it together!

  • Like 1

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 Noel Boss
      To create a new gitlab issue, I'd like to send an Email to the following email address using FormBuilder: 
      incoming+account/repository@incoming.gitlab.com
      unfortunately, the / in the email gets striped by the sanitizer:
      wire('sanitizer')->email(incoming+account/repository@incoming.gitlab.com'); // output: incoming+accountrepository@incoming.gitlab.com Is there any way to configure the sanitizer? Any other Ideas how to send the mail to this address?
       
      Ps.: I can not define the email format as it is defined by gitlab. The format is also kind of "common" and known as email-alias in the form of emailaccount+alias@domain.com – gmail uses it to label mails…
      https://help.wodify.com/hc/en-us/articles/234441508-How-Do-I-Create-an-Email-Alias-
    • By ihathome
      Hi,
      I'm an abolute newbie in processwire an it's modules. But I have read huge amounts of posts in this forum and as many docs and i learnt a lot in the last days. For a contact-form i used this great module (many thanks) and i hooked it my first time. Everything is alright. Now i search for a possibility to format or render the output in the email. Is there any posibility?
      Thank you for your replies
    • By Kiwi Chris
      Forms are an essential part of most websites, and it's no surprise that there's an excellent premium module Form Builder but what if you're on a zero budget for whatever reason?
      It is possible to build forms quickly and easily by making use of a couple of free modules and the admin UI to give you a great deal of flexibility and speed of development, particularly if you need multiple forms on a website with different fields.
      1. First you're going to need to install a couple of modules:
      Form Template Processor
      Fieldtype Select External Option
      2. For each form that you want to display, create a template without a template file and add fields to it as you normally would. (eg I have formContact, formRegister etc)
      Tip: under the Advanced tab in the setup for each template, I add a tag Forms so that all my forms templates are nicely grouped together in admin.
      3. Create a new field of type Select External Option and call it formTemplate
      In the section Create options from any database table select
      templates as the source table id as the Option Value name as the Option Label 4. Create a new template file and call it renderForm.php (or whatever else you like)
      Add an email field to this form - This will be the email address that forms get submitted to. Add the formTemplate field you previously created to this form. This will allow you to select which of the templates you previously created such as formContact, formRegister etc you want to render. Add any other fields as usual that you want to render on the page. Add the following PHP code to the template file. $recipient = $page->email; $form = $modules->get('FormTemplateProcessor'); $form->template = $templates->get($page->formTemplate->label); // required $form->requiredFields = array('contactName', 'contactEmail', 'contactMesssage'); //Optional: This can be improved by having a field in the page template with a CSV list of required fields eg $form->requiredFields = explode(',', $page->requiredFields) $form->email = $recipient; // optional, sends form as email. FormTemplateProcessor can also save forms to the database. $content .= $form->render(); //generate the form to display. Note: this doesn't actually render the form at this point, but you have it in the $content variable ready to output wherever you want in your template.
      Add any template HTML or other PHP code and echo $content; wherever you want to render the form.
      5. Create a page using the renderForm template, and provide an email address, and select a form that you want to display.
      6. Use CSS to style the form as required.
      7. View your new page, and check that the form renders correctly.
      8. You can modify the templates you created at step 2 or create new ones as required if your requirements for what fields forms display changes.
      Note: The Form Template Processor module can also save form input as pages, and the FieldType Select External Option can be set up with filtering, so this solution can probably be refined further.
    • By henri
      Hi Guys,
      i am a newbe to processwire. Have to maintain a website, but never worked with processwire. I have got an form that is submitted ( i do not have the form thing), to two email addresses. The last week the mails to the second address aren't delivered so it seems. Where do i find the email addresses where the form is submitted to?? I cant find them, though i can find the include of the form. Who knows?????
    • By Noel Boss
      This module hooks into the login method to provide the possibility to login with the user's email address. This is my first module and it's very simple. Please provide feedback if you have any suggestions. Thanks
      The module can be found in the module repository:
      https://modules.processwire.com/modules/login-with-email/
      or on github:
      https://github.com/noelboss/LoginWithEmail
       
×
×
  • Create New...