Showing posts with label php. Show all posts
Showing posts with label php. Show all posts

Monday, February 20, 2012

Using the JangoMail API in PHP

Since PHP 5 provided developers with the SoapClient class, it's a snap to consume SOAP-enabled web services in a PHP script.

This example demonstrates how to connect to the JangoMail API in order to get the email lists on your account. Download the source code for this example, insert your own JangoMail credentials, and you're ready to start integrating the JangoMail API with your php website.

// create a SoapClient object for the jangomail aPI
$client = 
    new SoapClient("http://api.jangomail.com/api.asmx?WSDL");

// set the parameter array for the
// Groups_GetList_String method
$param=array(
 'Username'=>'Your JangoMail Username',
 'Password'=>'Your JangoMail Password',
 'RowDelimiter'=>'<br/>',
 'ColDelimiter'=>' - ',
 'TextQualifier'=>''
); 

// using the JangoMail API
// call the Groups_GetList_String method
$result = $client->Groups_GetList_String($param);

// print the groups that were returned
print($result->Groups_GetList_StringResult);

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

?>