Jump to content

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);

?>

Edited by SocialCloud
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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.