Tuesday, November 23, 2010

Technical Notes: Using the JangoMail API with PHP

Cool Life Systems, a provider of custom business solutions, uses the JangoMail API with PHP to send emails. They have graciously allowed us to share a sample of the PHP code they use to integrate their system with JangoMail's email solution. We hope this is helpful to anyone looking to use the JangoMail API with PHP. Thanks, Cool Life Systems!

We have two samples available that allow a user to input all of the parameters required by the API in order to send out an email message.

PHP Sample #1: Send a Mass Email - allows a user to send a mass email to a specified group that is in their account using the SendMassEmail method at http://api.jangomail.com/api.asmx?op=SendMassEmail

<?php
                    
$client = new SoapClient('https://api.jangomail.com/api.asmx?WSDL');

$parameters = array
    (
        'Username'          => (string) 'username',
        'Password'          => (string) 'password',
        'FromEmail'         => (string)
'fromaddress@domain.com',
        'FromName'          => (string) 'name',
        'ToGroups'          => (string) 'group name',
        'ToGroupFilter'     => (string) '',
        'ToOther'           => (string) '',
        'ToWebDatabase'     => (string) '',
        'Subject'           => (string) 'Mass Subject',
        'MessagePlain'      => (string) 'Mass Plain (plain text)',
        'MessageHTML'       => (string) 'Mass HTML (html) <br><a href="http://
www.google.com">Link #1</a>',
        'Options'           => (string) 'OpenTrack=True,ClickTrack=True'
    );
   
try
{
    $response = $client->SendMassEmail($parameters);
    echo "Message(s) sent!";
}
catch(SoapFault $e)
{
    echo $client->__getLastRequest();
}

?>

PHP Sample #2: Send a Transactional Email - allows a user to send a transactional email to a recipient that they specify using the SendTransactionalEmail method at http://api.jangomail.com/api.asmx?op=SendTransactionalEmail

<?php
               
$client = new SoapClient('https://api.jangomail.com/api.asmx?WSDL');

$parameters = array
    (
        'Username'          => (string) 'username',
        'Password'          => (string) 'password',
        'FromEmail'         => (string) 'fromaddress@domain.com',
        'FromName'          => (string) 'name',
        'ToEmailAddress'    => (string) 'recipient@domain.com',
        'Subject'           => (string) 'Transactional Subject',
        'MessagePlain'      => (string) 'Transactional Plain (plain text)',
        'MessageHTML'       => (string) '<b>Transactional HTML</b> (html)',
        'Options'           => (string) 'OpenTrack=True,ClickTrack=True'
    );
   
try
{
    $response = $client->SendTransactionalEmail($parameters);
    echo "Message(s) sent!";
}
catch(SoapFault $e)
{
    echo $client->__getLastRequest();
}

?>