Perl Fax – Using SendCharFax to Send Plain-Text Faxes

25 Nov 2016 This code sample is deprecated and in process of being removed. Check out our new code libraries and usage documentation on InterFAX @ Github.
Download the Perl fax code samples.

This example illustrates how to send a plain-text Perl fax, using the SendCharFax method. Using HTML causes automatic word wrapping, whereas regular text does not. Text is limited to be standard ASCII (no 8-bit characters), but can also include HTML markup.

In the Perl fax script below, a plain-text file is submitted to the Web service, and the submission’s success/failure is indicated: The return value of a successful submission is the (positive number) transaction ID of the fax in the system. Other return values indicate a failure (for more details, see Web Service Return Codes).


#/**************** Settings begin **************/
my $username  = ''; # Enter your Interfax username here
my $password  = ''; # Enter your Interfax password here
# Enter the destination fax number here in the format:
# +[country code][area code][fax number] for example: +1212555487
my $faxNumber = ''; 
my $textToFax  = 'My text goes here';
# If $textToFax holds regular text, enter "TXT" here.
# If $textToFax holds HTML enter "HTML" here 
my $filetype  = 'TXT';
my $NS = 'http://www.interfax.cc';
#/**************** Settings end ****************/

my $client = SOAP::Lite
    ->uri($NS)
    ->on_action( sub { join '/', $NS, $_[1] } ) 
    ->proxy('https://ws.interfax.net/dfs.asmx?wsdl');

my $result = $client
    ->call(SOAP::Data->name('SendCharFax')->attr({xmlns => $NS}) =>
                    SOAP::Data->name('Username')->value($username)->type(''),
            SOAP::Data->name('Password')->value($password)->type(''),
            SOAP::Data->name('FaxNumber')->value($faxNumber)->type(''),
            SOAP::Data->name('Data')->value($textToFax)->type(''),
            SOAP::Data->name('FileType')->value($filetype)->type('')
    );


if ( $result->fault ) {
    print $result->faultstring . "\n";
} else {
    if( $result->valueof('//SendCharFaxResult') > 0 ) {
        print "Success. TransactionID=" . $result->valueof('//SendCharFaxResult') . "\n";
    } else {
        print "Error, return code=" . $result->valueof('//SendCharFaxResult') . "\n";
    }
}
‹ Perl Fax - Send Binary Files Using SendFax