Re: Variable scope

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




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@xxxxxxxxx> ;
$from = Member <member@xxxxxxxxxxx>;

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@xxxxxxxxx> ;
but it wont send because the smtp mail will not send to
$To = John Doe &lt;jdoe@xxxxxxxxx&gt;

I MUST be doing something wrong.
Also, I did read about using Name <email@xxxxxxxxx> 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



--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux