PHP Free Chat – Joining Chat Email Notification

I recently upgraded an install of PHP Free Chat to that latest version of 1.0 Final. However it was still lacking a feature to notify individual(s) that someone has joined the chat if they were not already in the chat application to begin with. I came across a posting explaining how to achieve this in PHP Free Chat at PHP Free Chat Forum. After a little reading and discussion I was able to implement the feature.

Here’s my modified version for the solution based on the forum posting. The pfcmail() function can be made to be way more versatile for any use, however for my use it was made to be simple and produce properly formated email messages.

Solution


  1. Create a new PHP file called pfcmail.php with the following lines of code.
  2. 1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    
    < ?php
    function pfcmail($szChannel,$szNickname)
    {
    	$szCurrentDateTime = date('F j, Y @ g:i:sa', time());
    	$szClientIP = getenv("REMOTE_ADDR");
    	$szHostName = gethostbyaddr("$szClientIP");
    	$szServerName = getenv("SERVER_NAME");
    	$szEmailWebmaster = getenv("SERVER_ADMIN");
     
    	$szEmailTo = "Webmaster <$szEmailWebmaster>";
    	$szMsgHeaders = "From: $szEmailWebmaster\r\n";
    	$szMsgHeaders .= "X-Mailer: PHP\r\n";
    	$szMsgHeaders .= "MIME-Version: 1.0\r\n";
    	$szMsgHeaders .= "Content-type: text/plain; charset=UTF-8";
    	$szMsgSubject = "[WEB] Chat Login - $szNickname in channel $szChannel at $szCurrentDateTime";
     
    	$szMsgBody = "Date\t\t\t\t: $szCurrentDateTime\n";
    	$szMsgBody .= "Server Name\t\t\t: $szServerName\n";
    	$szMsgBody .= "Client IP\t\t\t: $szClientIP\n";
    	$szMsgBody .= "Client Hostname\t\t: $szHostName\n\n";
     
    	$szMsgBody .= "Join chat now by going to http://$szServerName/chat/index.php.\n\n";
     
    	$szMsgBody .= "---\n";
    	$szMsgBody .= "Email message auto-generated by PHP mail().";
     
    	$nSendEmail = mail($szEmailTo, $szMsgSubject, $szMsgBody, $szMsgHeaders);
    }
    ?>
    Note: The extra r, n and t’s should have a \ character before them to produce a carriage return, new line and tab. WordPress appears to remove the character.
  3. Make sure to modifiy the code in pfcmail.php for the To, from, subject and body of the email message to your requirements.
  4. Save pfcmail.php file into the following path, /src/commands/.
  5. Edit /src/commands/nick.class.php at line number 84, just before “return true;” add the following code and save.
  6. require_once(dirname(__FILE__).”/pfcmail.php”);
    pfcmail($c->title, $newnick);

You should now be receiving email notifications each time an individual joins chat.

One thought on “PHP Free Chat – Joining Chat Email Notification

  1. Your blog is amazing, i first landed to another post but then get interested and thought, i will just look a little more arround to see what else i can find out about such stuff :-)

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">