Jump to content

creating a function


runnerjp

Recommended Posts

<?php

class Mailer {

function Mailer() {
	// Class constructor
}

/*
* sendWelcome - Sends a welcome message to the newly
* registered user, also supplying the username and
* password.
*/  
function sendWelcome($user, $email, $pass){
	$from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
	$subject = "runnerselite - registration";
	$body = $user.",\n\n"
	."We've generated a new password for you at your "
	."request, you can use this new password with your "
	."username to log in to runnerselite.\n\n"
	."Username: ".$user."\n"
	."New Password: ".$pass."\n\n";
	$key = randomkeys(16);   
	$body .= "http://runnerselite.com/login/activate.php?id=". $key ."\n\n";
	return mail($email,$subject,$body,$from);
}

/**
* sendNewPass - Sends the newly generated password
* to the user's email address that was specified at
* sign-up.
*/
function sendNewPass($user, $email, $pass){
	$from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
	$subject = "Jpmaster77's Site - Your new password";
	$body = $user.",\n\n"
	."We've generated a new password for you at your "
	."request, you can use this new password with your "
	."username to log in to Jpmaster77's Site.\n\n"
	."Username: ".$user."\n"
	."New Password: ".$pass."\n\n"
	."It is recommended that you change your password "
	."to something that is easier to remember, which "
	."can be done by going to the My Account page "
	."after signing in.\n\n"
	."- Jpmaster77's Site";

	return mail($email,$subject,$body,$from);
}
}

/* Initialize mailer object */
$mailer = new Mailer;

?>

 

You had both functions in your class called the same thing.

yes i found that 1 out im gtting Fatal error: Call to a member function on a non-object in /home/runnerse/public_html/website/login/include/mailer.php on line 5

 

 

<?php
class Mailer
{
function sendWelcome($user, $email, $pass){
$key = $database->randomkeys(16);   
      $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
      $subject = "runnerselite - registration";
      $body = $user.",\n\n"
             ."We've generated a new password for you at your "
             ."request, you can use this new password with your "
             ."username to log in to runnerselite.\n\n"
             ."Username: ".$user."\n"
             ."New Password: ".$pass."\n\n";              
$body .= "http://runnerselite.com/login/activate.php?id=". $key ."\n\n";
      return mail($email,$subject,$body,$from);
} 


}
/* Initialize mailer object */
$mailer = new Mailer;

?> 

<?php
class Mailer
{
global $database;
$key = $database->randomkeys(16); 
function sendWelcome($user, $email, $pass){  
      $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
      $subject = "runnerselite - registration";
      $body = $user.",\n\n"
             ."We've generated a new password for you at your "
             ."request, you can use this new password with your "
             ."username to log in to runnerselite.\n\n"
             ."Username: ".$user."\n"
             ."New Password: ".$pass."\n\n";              
$body .= "http://runnerselite.com/login/activate.php?id=". $key ."\n\n";
      return mail($email,$subject,$body,$from);
} 


}
/* Initialize mailer object */
$mailer = new Mailer;

 

 

I GOT THE ERROR Parse error: syntax error, unexpected T_GLOBAL, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /home/runnerse/public_html/website/login/include/mailer.php on line 4

Do more research in regards to php classes and the all-important concept of 'scope'.  The reason why your function isn't working is because in the scope of the class, it hasn't been declared yet.  You should consider a class to be completely separate from any other script, no matter where the class resides.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.