Variable scope

From: Date: Thu, 14 Jul 2011 20:54:28 +0000
Subject: Variable scope
Groups: php.general 
Request: Send a blank email to php-general+get-314078@lists.php.net to get a copy of this message
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 ; 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!?!? 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 (#314078) next »