0

Hey all, Kinda new to php but have managed to create a website with a login script (cheated and used usercake) but have modified it to my own needs mostly. However I now need to make it so that when the user registers it sends it to me not to the user (so that I can approve it), Have gone through and found what I think is mostly it but still a little confused and wondered if I can get some pointers as to what to change to make it do this.

I currently have a register page, which checks the following three files:

newuser.php

//Do we need to send out an activation email?
            if($emailActivation == "true")
            {
                //User must activate their account first
                $this->user_active = 0;

                $mail = new userCakeMail();

                //Build the activation message
                $activation_message = lang("ACCOUNT_ACTIVATION_MESSAGE",array($websiteUrl,$this->activation_token));

                //Define more if you want to build larger structures
                $hooks = array(
                    "searchStrs" => array("#ACTIVATION-MESSAGE","#ACTIVATION-KEY","#USERNAME#"),
                    "subjectStrs" => array($activation_message,$this->activation_token,$this->displayname)
                    );

                /* Build the template - Optional, you can just use the sendMail function 
                Instead to pass a message. */

                if(!$mail->newTemplateMsg("new-registration.txt",$hooks))
                {
                    $this->mail_failure = true;
                }
                else
                {
                    //Send the mail. Specify users email here and subject. 
                    //SendMail can have a third parementer for message if you do not wish to build a template.

                    if(!$mail->sendMail($this->clean_email,"New User"))
                    {
                        $this->mail_failure = true;
                    }
                }
                $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE2");
            }
            else
            {
                //Instant account activation
                $this->user_active = 1;
                $this->success = lang("ACCOUNT_REGISTRATION_COMPLETE_TYPE1");
            }   

class.mail.php

<?php


class userCakeMail {

    public $contents = NULL;

    //Function used for replacing hooks in our templates
    public function newTemplateMsg($template,$additionalHooks)
    {
        global $mail_templates_dir,$debug_mode;

        $this->contents = file_get_contents($mail_templates_dir.$template);

        //Check to see we can access the file / it has some contents
        if(!$this->contents || empty($this->contents))
        {
            return false;
        }
        else
        {
            //Replace default hooks
            $this->contents = replaceDefaultHook($this->contents);

            //Replace defined / custom hooks
            $this->contents = str_replace($additionalHooks["searchStrs"],$additionalHooks["subjectStrs"],$this->contents);

            return true;
        }
    }

    public function sendMail($email,$subject,$msg = NULL)
    {
        global $websiteName,$emailAddress;

        $header = "MIME-Version: 1.0\r\n";
        $header .= "Content-type: text/plain; charset=iso-8859-1\r\n";
        $header .= "From: ". $websiteName . " <" . $emailAddress . ">\r\n";

        //Check to see if we sending a template email.
        if($msg == NULL)
            $msg = $this->contents; 

        $message = $msg;

        $message = wordwrap($message, 70);

        return mail($email,$subject,$message,$header);
    }
}

?>

function.php

//Input new activation token, and update the time of the most recent activation request

function updateLastActivationRequest($new_activation_token,$username,$email)

{

    global $mysqli,$db_table_prefix;    

    $stmt = $mysqli->prepare("UPDATE ".$db_table_prefix."users

        SET activation_token = ?,

        last_activation_request = ?

        WHERE email = ?

        AND

        user_name = ?");

    $stmt->bind_param("ssss", $new_activation_token, time(), $email, $username);

    $result = $stmt->execute();

    $stmt->close(); 

    return $result;

}



//Generate a random password, and new token

function updatePasswordFromToken($pass,$token)

{

    global $mysqli,$db_table_prefix;

    $new_activation_token = generateActivationToken();

    $stmt = $mysqli->prepare("UPDATE ".$db_table_prefix."users

        SET password = ?,

        activation_token = ?

        WHERE

        activation_token = ?");

    $stmt->bind_param("sss", $pass, $new_activation_token, $token);

    $result = $stmt->execute();

    $stmt->close(); 

    return $result;

}
1
Contributor
1
Reply
10
Views
3 Years
Discussion Span
Last Post by marriott81
0

For anyone curious:

the fix is super simple. In models/class.newuser.php around Line 95 you will see the following line:

Code:
if(!$mail->sendMail($this->clean_email,"New User"))

Simply replace $this->clean_email with your e-mail address so it looks as so:

Code:
if(!$mail->sendMail("admin_email@usercakeisfun.com","New User"))

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.