Paul's Programming Notes     Archive     Feed     Github

WHMCS Hook - Trigger E-mail On New User Sign-Up

This script needs to go into your WHMCS hooks folder (root/includes/hooks/):

<?php

 function send_invitiation_email($vars) {

     $command = "sendemail";
$adminuser = "admin"; // Your admin username
$values["messagename"] = "Google Groups Invitation"; // exact name of e-mail template
$values["id"] =  $vars['userid'];

$results = localAPI($command,$values,$adminuser);

 }

 add_hook("ClientAdd",1,"send_invitiation_email");

 ?>

UnicodeEncodeError: 'ascii' codec can't encode character u'\ufffd' in position 12: ordinal not in range(128)

The error in the title will occur on pre-0.12.0 versions of python’s Requests library. It seems to be fixed on later versions and maybe even earlier.

Here’s an example of how you save a zip file from behind a corporate proxy with python’s Requests library:

That’s it! Just use the write function with the content of the returned request.

Writing To File - UnicodeEncodeError: 'ascii' codec can't encode characters

I was getting a lot of errors when I was trying to download a file with the python requests library. The errors looked like the following:

UnicodeEncodeError: ‘ascii’ codec can’t encode characters in position 2-6: ordinal not in range(128)

This code ended up fixing it: