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.'/SforceEnterpriseClient.php');

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

  $singleEmail1 = new SingleEmailMessage();
  $singleEmail1->setToAddresses(array("youremail@email.com"));
  $singleEmail1->setPlainTextBody('My message');
  $singleEmail1->setSubject("A Single Email");
  $singleEmail1->setSaveAsActivity(true);
  $singleEmail1->setEmailPriority(EMAIL_PRIORITY_LOW);
  
  echo "***** Send Emails *****\n";
  $emailResponse = $mySforceConnection->sendSingleEmail(array($singleEmail1));

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

Sample Output

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

You should also get an email titled "A Single Email".

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->setSaveAsActivity(true);
  $massEmail->setEmailPriority(EMAIL_PRIORITY_LOW);
  $massEmail->setTemplateId("00X50000000wX9q");
  $massEmail->setTargetObjectIds(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
)

An email should get sent to the email associated with the targeted object.