Contents

Send Single Email Message

Sample Call

<?php
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.ocm password

define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');

try {
  $mySforceConnection = new SforcePartnerClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
  $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

  $singleEmail1 = new SingleEmailMessage();
  $singleEmail1->toAddresses = "email1@test.com";
  $singleEmail1->plainTextBody = "Hello there";
  $singleEmail1->subject = "First Single Email";
  $singleEmail1->saveAsActivity = true;
  $singleEmail1->emailPriority = EMAIL_PRIORITY_LOW;

  $singleEmail2 = new SingleEmailMessage();
  $singleEmail2->toAddresses = "email2@testcom";
  $singleEmail2->plainTextBody = "Hello there";
  $singleEmail2->subject = "Second Single Email";
  $singleEmail2->saveAsActivity = true;
  $singleEmail2->emailPriority = EMAIL_PRIORITY_LOW;

  echo "***** Send Emails *****\n";
  $emailResponse = $mySforceConnection->sendSingleEmail(array ($singleEmail1, $singleEmail2));

  print_r($emailResponse);

} catch (Exception $e) {
  echo $mySforceConnection->getLastRequest();
  echo $e->faultstring;
}
?>

Sample Output

***** Send Emails *****
Array
(
    [0] => stdClass Object
        (
            [success] => 1
        )

    [1] => stdClass Object
        (
            [success] => 1
        )
)

You should also get two emails.

Send Mass Email Message

Sample Call

<?php
// SOAP_CLIENT_BASEDIR - folder that contains the PHP Toolkit and your WSDL
// $USERNAME - variable that contains your Salesforce.com username (must be in the form of an email)
// $PASSWORD - variable that contains your Salesforce.ocm password

define("SOAP_CLIENT_BASEDIR", "../../soapclient");
require_once (SOAP_CLIENT_BASEDIR.'/SforcePartnerClient.php');

try {
  $mySforceConnection = new SforcePartnerClient();
  $mySoapClient = $mySforceConnection->createConnection(SOAP_CLIENT_BASEDIR.'/partner.wsdl.xml');
  $mylogin = $mySforceConnection->login($USERNAME, $PASSWORD);

  $massEmail = new MassEmailMessage();
  $massEmail->subject = "Nicks Mass Email Message";
  $massEmail->saveAsActivity = true;
  $massEmail->emailPriority = EMAIL_PRIORITY_LOW;
  $massEmail->templateId = "00X50000000wX9q";
  $massEmail->targetObjectIds = array ("0035000000PiCMd");

  echo "***** Send Emails *****\n";
  $emailResponse = $mySforceConnection->sendMassEmail(array($massEmail));
  print_r($emailResponse);
  
} catch (Exception $e) {
  echo $mySforceConnection->getLastRequest();
  echo $e->faultstring;
}
?>

Sample Output

***** Send Emails *****
stdClass Object
(
    [success] => 1
)