Possibility to receive a mail for each registering of a new member ?

OSSN USER Posted in General Discussion 7 years ago

Hello,

I would like to receive an email for each registering of a new member.
I created an email box especially for that. I made some tests of registering but i don't receive anything in the mail box created for that.
I put this email address in the notification field in admin panel (and the email address is the good one, no error in the address).

Did I forgot something ?
If it is possible to do it, in which file the email is configured ?
Thanks
OSSN User

Replies
Dutch OSSN USER Replied 7 years ago

Thanks a lot Mr ZetMan, that's really what i wanted to do.
Now i made my formular registration exactly how I wanted to do it
but without your help, i won't found how to do it.
Thanks again

German Michael Zülsdorff Replied 7 years ago

Perfect find, OSSN USER!

Your own code has to be inserted exactly after

if ($add->addUser()) {

so let's add a comment there, first

if ($add->addUser()) {
    // OSSN USER custom code

As already mentioned the NotifiyUser function of the OssnMail class does exactly what you want. It's just waiting to be instantiated and called with the right parameters. So let's have a look into classes/OssnMail.php line 15:

public function NotifiyUser($email, $subject, $body)

Ok: we need a mail address, in this case your own one, a subject and the mail body.
You may hardcode all that, but having a later component in mind it's more convenient to use variables if in place. Thus, let's do a litte excursion, start your PHPMyAdmin tool and look into the ossn_site_settings table.

The column of main interest is owner_email, the address you want to send your notification to. But it's good to know that any value of this table can be easily retrieved by the function ossn_site_settings("COLUMN_NAME"); That said we're ready now to prepare the function parameters like

$email = ossn_site_settings('owner_email');

Then, your subject may look like

$subject = ossn_site_settings('site_name') . ' User Registration';

And finally the body part ...

$body = 'Username: ' . $add->username . ' has successfully registered.';

Of course you may add any other available member data to your string.

Now, as all function parameters are correctly prepared we only need a new instance of the OssnMail class

$admin_message = new OssnMail;

and call the NotifiyUser function with the above prepared parameters ...

$admin_message->NotifiyUser($email, $subject, $body);

That's it. :)

To sum it up your code would look like

if ($add->addUser()) {
    // OSSN USER custom code start
    $email = ossn_site_settings('owner_email');
    $subject = ossn_site_settings('site_name') . ' User Registration';
    $body = 'Username: ' . $add->username . ' has successfully registered.';
    $admin_message = new OssnMail;
    $admin_message->NotifiyUser($email, $subject, $body);
    // OSSN USER custom code end

Keep in mind that this core file will be overwritten by the next Ossn update. Thus transforming it into a component would be the next exercise. :)

Dutch OSSN USER Replied 7 years ago

ZetMan, for me , at first, the file to change was registrer.php (after you have talked about OssnMail so i thought i was wrong).

For me the lines where the new members are added are :

if ($add->addUser()) {
$em['success'] = 1;
$em['datasuccess'] = ossnprint('account:created:email');
echo json
encode($em);

I put my email address beside of $em (separated by a ",") but the formular is down. i tried echo jsonencode($em , myaddressemail); or echo jsonencode($em , 'myaddressemail');

Catalan James MacKay Replied 7 years ago

Sorry, did not mean to offend, just offering a suggestion as I was not able to get my registration email working either until I did what I did. PS, I am in no way trying to promote an illegal web site.
I will do everyone a favor and just shut up and read the discussions.

German Michael Zülsdorff Replied 7 years ago

No, don't change Ossn classes!!!
You had the right thought in the beginning: You want to enhance the register action.
When a user has been added successfully to the database, you want to send a mail to yourself, right?
So

  1. make a backup of actions/user/register.php first
  2. then open register.php in your editor and try to find the line where
    the new member was added.

Can you tell it?

Dutch OSSN USER Replied 7 years ago

You are right for James , his post is offside and i think it is a way for him to promote an illegal website...

I don t understand where to put my email address to recover the mail of regristering.
I saw a $em (i think it is the variable for the email). The file to modify is the OssnMail.php ?

German Michael Zülsdorff Replied 7 years ago

@James
Your comments are off topic and irritating.
@OSSN USER
you already found the right starting point - what exactly don't you understand?

Dutch OSSN USER Replied 7 years ago

When you are not developper, just that is impossible to do.

Catalan James MacKay Replied 7 years ago

I also used the footer links to have a contact link for users to contact me directly.

Catalan James MacKay Replied 7 years ago

And if you don't have your own email server and dedicated static IP, you can always use your gmail account to bounce those registration messages from your website to your email inbox..... that's what I do because I have a dynamic IP and could not get an email server to communicate with other mail servers properly. You still need to utilize ossnmail (and it is not hard to configure) unless you have your own domain mail server like mail.facecrack.net.