Re: Variable scope

From: Date: Thu, 14 Jul 2011 21:23:50 +0000
Subject: Re: Variable scope
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-314081@lists.php.net to get a copy of this message
On Jul 14, 2011, at 3:54 PM, Karl DeSaulniers wrote:
Can anyone explain this to me. function sendEmail($uname,$subjField,$firstname,$lastname,$email,$reply,$e_cc,$e_bcc,$comments,$ip,$Date,$time){ $uname = trim($uname); $subjField = trim($subjField); $firstname = trim($firstname); $lastname = trim($lastname); $email = trim($email); $reply = trim($reply); $e_cc = trim($e_cc); $e_bcc = trim($e_bcc); $comments = trim($comments); $ip = trim($ip); $Date = trim($Date); $time = trim($time); //If I trace here email, reply and the CCs are ok if(($firstname && strlen($firstname = trim($firstname)) > 2) && ($lastname && strlen($lastname = trim($lastname)) > 2)) { $fullname = $firstname." ".$lastname; } else { $fullname = "Member"; } $fullname = trim($fullname); $To = ""; $from = ""; $headerTXT = ""; $bounce_email = CO_NAME." <".BOUNCE_ADDR.">"; $subject = $subjectField; $bulk = false; //What kind of email is being sent //Email exists, no Cc or Bcc if(!empty($email) && empty($_email_cc) && empty($_email_bcc)) { $To = $fullname." <".$email.">"; $from = "Member <".$reply.">"; $headerTXT = "New message from ".CO_NAME." member ".$uname; $bulk = false; } //Email empty, Cc exists no Bcc else if(empty($email) && !empty($e_cc) && empty($e_bcc)) { $To = $bounce_email; $from = "Member <".$reply.">"; $headerTXT = "New message from ".CO_NAME." member ".$uname; $bulk = true; } ... //If I trace here $To, $from have everything except the "<(anything between)>", so for instance.. $To = John Doe ; $from = Member ;
Have you looked at the output in the page source? The <> may be getting eaten by the browser. You may want to use htmlentities on your trace output (but not the actual variables).
not $To = John Doe <jdoe@email.com> ; $from = Member <member@company.com>; So $email and $reply are loosing their value/scope But the ".CO_NAME." and ".BOUNCE_ADDR." are working!?!?
I assume these are defined constants, which don't have scope (or, perhaps more accurately, always have global scope).
This is also in a page with many other email functions just like this one and they work. Only difference is the $To and $from are not inside an if() { statement. How did my variables loose scope??? One other note, if I put.. $To = htmlspecialchars($fullname." <".$email.">"); then $To is correct when I trace.. $To = John Doe <jdoe@email.com> ; but it wont send because the smtp mail will not send to $To = John Doe &lt;jdoe@email.com&gt; I MUST be doing something wrong. Also, I did read about using Name <email@email.com> but the other email functions work fine with those, so I'm not sure what's going on. TIA, Best, Karl DeSaulniers Design Drumm http://designdrumm.com


« previous php.general (#314081) next »