Global var in mail class file
Permalink
Hi a client of mine wanted to add something to their mailtemplate, i've put the var in a session and included the session in the mail.php file and when i echo it in the beginning of the file i see the var.
But i need the var to be able to load INSIDE the class and inside a function.
How do i do this?
Cause the normal way with global doesn't seem to be working.
You can see the var in line 2&3.
And i want the var to be useable on line 122-124.
I have already typed what i think it should be but it doesn't work could someone please check it out for me?
Probably a VERY stupid thing...
(mail.php as attachment included)
Thanks in advance!
But i need the var to be able to load INSIDE the class and inside a function.
How do i do this?
Cause the normal way with global doesn't seem to be working.
You can see the var in line 2&3.
And i want the var to be useable on line 122-124.
I have already typed what i think it should be but it doesn't work could someone please check it out for me?
Probably a VERY stupid thing...
(mail.php as attachment included)
Thanks in advance!
i understand you but it has to show up on every mail that has been send by the site.
the value needs to come in the From:
But therefore i need to get the var inside the sendMail()
and the $mh will not work when there's a new or custom made form right?
Or can i use it before the class to?
Cause i tried that with an example from register.php but it didn't work :(.
I'm just looking to get the var that's before my class to get it inside my class.
Thanks in advance!
the value needs to come in the From:
But therefore i need to get the var inside the sendMail()
and the $mh will not work when there's a new or custom made form right?
Or can i use it before the class to?
Cause i tried that with an example from register.php but it didn't work :(.
I'm just looking to get the var that's before my class to get it inside my class.
Thanks in advance!
I'm really too sure what you're trying to do then. Sounds like your having an issue with php itself rather than concrete. and yes, the MailHelper should be flexible enough to be used on your own custom forms.
Ok i'll try and explain, in the header of the cms i have added $_SESSION['referrer'] with a value in it.
Now i have added the value to the mail.php file and when i echo it before where the class starts it shows up so it works.
But i need to add the value in the "From:" line from every mail that's been sent from the website.
That's about it.
And thanks for your patience!
Now i have added the value to the mail.php file and when i echo it before where the class starts it shows up so it works.
But i need to add the value in the "From:" line from every mail that's been sent from the website.
That's about it.
And thanks for your patience!
anyone please?:(
can someone still please help me i'm really stuck...
Thanks in advance!
Thanks in advance!
try zipping and posting you're files. it's sorta hard to find people's bugs when you have no idea what their code looks like.
Files i used are included...
So i've made a new file in the corefolder named "function_redirect.php" and included it in "header.php".
Now i want the value of the variable that's in my session to parse it to the mail.php file, so it can be used as the "From:" in every mail that has been send.
That's all, everything works, i get the var in the mail.php file, but i can't get it in the class itself...
Thats all that needs to be done actually.
Thanks man!
So i've made a new file in the corefolder named "function_redirect.php" and included it in "header.php".
Now i want the value of the variable that's in my session to parse it to the mail.php file, so it can be used as the "From:" in every mail that has been send.
That's all, everything works, i get the var in the mail.php file, but i can't get it in the class itself...
Thats all that needs to be done actually.
Thanks man!
anyone please? thanks in advance!
first I wouldn't worry about calling session_start anyway. Concrete should have started a session already, so you can probably comment those out.
now, your problem with that variable not showing up in your class is a scope issue. In languages like javascript, you can create a variable outside of a function and have it available to other functions, like you're trying to do. In php however, you have to explicitly make it available within your sendMail method by first calling:
Some people consider using globals bad practice though, so you should probably just grab that variable from the session inside of that method. This will avoid the scope issue altogether:
now, your problem with that variable not showing up in your class is a scope issue. In languages like javascript, you can create a variable outside of a function and have it available to other functions, like you're trying to do. In php however, you have to explicitly make it available within your sendMail method by first calling:
public function sendMail() { global $referrer; ... }
Some people consider using globals bad practice though, so you should probably just grab that variable from the session inside of that method. This will avoid the scope issue altogether:
public function sendMail() { $referrer = $_SESSION['referrer']; ... }
$mh->addParameter('myVariable', "This is the string being held by my variable");
and within your mail template $myVariable would then be accessible.
Check out the c5root/concrete/controllers/login.php and register.php files for examples of uses the mail helper.
Also, if you're making changes to any of these core controller, you may want to override them so they don't get nixed during your next upgrade.