Jump to content

Help With Functions?


Kryllster

Recommended Posts

I have written some code which I am not trying to put in a function but I am new to functions so I am not sure what to do. It is an Email account activation script I know it works as it is now but I wanted to try my hand at making it a function.

 

=========================

$activationkey = hash('adler32',rand());
function emailActivate($email_to,$email_subject,$returnlink,$email_message,$activationkey){
$email_to = $_POST['email'];
$email_subject = "Email Verification and Activation";
$returnlink = "http://ferentus.netai.net/php/verify.php?code=" . $activationkey;
$email_message = "Welcome to The Ferentus Text Website, Please verify your email and activate your account by clicking the link.\n" . $returnlink;
mail($email_to,$email_subject,$email_message);
}
?>

 

========================================

Im stuck as to how to use this or even if it is correct? Any comments would be appreciated!!

Link to comment
https://forums.phpfreaks.com/topic/271977-help-with-functions/
Share on other sites

Short version: functions don't run automatically. You need to call them by using

function_name(variables, variables);

 

$_POST will not work in a function so you need to call them by the variables inside the parentheses

 

ie:

 

functions.php

 

// variables can stay the same it doesn't matter just as long as they coincide
function bored($bored_renamed, $tired) {

echo "Bored = $bored_renamed";

}

 

whatever.php

<?php
require("functions.php");

bored($bored, $sleepy);

?>

Link to comment
https://forums.phpfreaks.com/topic/271977-help-with-functions/#findComment-1399287
Share on other sites

$_POST will not work in a function so you need to call them by the variables inside the parentheses

 

@SocialCloud

 

I think you need to RTFM re superglobals

http://php.net/manual/en/language.variables.superglobals.php

Link to comment
https://forums.phpfreaks.com/topic/271977-help-with-functions/#findComment-1399293
Share on other sites

<?php
// mail going to the person who signed up for game
$email_to = $_POST['email'];
// self explanatory
$email_subject = "Email Verification and Activation";
// needed help from emeri for this
$returnlink = "http://ferentus.netai.net/php/verify.php?code=" . $activationkey;
//send the message
$email_message = "Welcome to The Ferentus Text Website, Please verify your email and activate your account by clicking the link.\n" . $returnlink;
// action taken
mail($email_to,$email_subject,$email_message);
?>

 

========================================

This is the way I had been using it is it even necessary to use it in a function??

Link to comment
https://forums.phpfreaks.com/topic/271977-help-with-functions/#findComment-1399295
Share on other sites

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.