Kryllster Posted December 14, 2012 Share Posted December 14, 2012 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!! Quote Link to comment https://forums.phpfreaks.com/topic/271977-help-with-functions/ Share on other sites More sharing options...
trq Posted December 14, 2012 Share Posted December 14, 2012 Yep, you seem completely lost. Have you tried reading the manual? Quote Link to comment https://forums.phpfreaks.com/topic/271977-help-with-functions/#findComment-1399282 Share on other sites More sharing options...
Kryllster Posted December 14, 2012 Author Share Posted December 14, 2012 Thanks for the reply. I am looking in the manual now altho it doesnt seem to help much I will also look at some online tutorials. Quote Link to comment https://forums.phpfreaks.com/topic/271977-help-with-functions/#findComment-1399286 Share on other sites More sharing options...
MDCode Posted December 14, 2012 Share Posted December 14, 2012 (edited) 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); ?> Edited December 14, 2012 by SocialCloud Quote Link to comment https://forums.phpfreaks.com/topic/271977-help-with-functions/#findComment-1399287 Share on other sites More sharing options...
Barand Posted December 14, 2012 Share Posted December 14, 2012 $_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 Quote Link to comment https://forums.phpfreaks.com/topic/271977-help-with-functions/#findComment-1399293 Share on other sites More sharing options...
Kryllster Posted December 14, 2012 Author Share Posted December 14, 2012 <?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?? Quote Link to comment https://forums.phpfreaks.com/topic/271977-help-with-functions/#findComment-1399295 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.