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();
}

?>

5 comments:

  1. Christopher11:14 AM

    Awesome! I have looking for something just like this...

    ReplyDelete
  2. Using the JangoMail API in PHP applications has been a very smooth experience, the API documentation and fast responses from the JangoMail support team made a huge difference during the development process.

    ReplyDelete
  3. Anonymous12:18 AM

    wow the technical support seems to be online at any time !!

    ReplyDelete
  4. Anonymous9:43 AM

    Fatal error: Class 'SoapClient' not found in C:\wamp\www\mail.php on line 3

    I got this error while executing this code

    ReplyDelete
  5. When receiving an error stating that the 'SoapClient' Class could not be found, it typically means that it's not installed on your web server. You should check with your web hosting provider to see if they can make this available. Some web hosting providers allow you to switch the version of PHP you're using with your account as well, and I've found that some higher versions already have this installed.

    ReplyDelete

Please note: spam posts will be marked as spam and deleted.