As far as I can tell you’re literally attempting to join the channel $chan. So
“JOIN $chan\r\n”
should be
“JOIN “.$chan.”\r\n”
or
“JOIN {$chan}\r\n”
The same for both of your PRIVMSG
As far as I can tell you’re literally attempting to join the channel $chan. So
“JOIN $chan\r\n”
should be
“JOIN “.$chan.”\r\n”
or
“JOIN {$chan}\r\n”
The same for both of your PRIVMSG