function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Looking for "sendEmail" example

I'm currently trying to get the new API command "sendEmail" to work with PHP/nusoap - so far it is just throwing various error messages ;-)
Can someone please provide an example - PHP would be great, but an XML/SOAP snippet of the actual API call would to it as well. Thanks in advance!
Does anyone have a clue?!
The sendmail function is not supported in the NuSoap implementation, and probably will not be unless someone wants to write new code.
The sendmail function also is not supported in the current toolkit (which requires php 5.1 or later). Hopefully it will get added there sometime in the future.
In the meantime, you can use the mail function in php to actually send the messages. Then create email activities after the message is sent.
This is the code I use to send email messages in php.
try {
        // Send the messages
        // Text of the message sent to invitees.
    $mailMessage = "<html><p>Your message goes here</p><html>";
    $subject = "Message Subject";
    $headers = "From: ".$senderEmail."\r\n";
    $headers .= "Reply-To: ".$senderEmail."\r\n";
    $headers .= "MIME-Version: 1.0" . "\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1" . "\r\n";
    $headers .= "X-Mailer: PHP/".phpversion();

    $mailSent = array();  
    foreach ($validInvites as $invite) {
        if ($messageCount < $maxMessages) {
            $mailed = mail($invite->fields['Email__c'], $subject, $mailMessage, $headers);
            if ($mailed) {
                $sObject = new SObject();
                $sObject->type = "Census_Messages__c";
                $sObject->fields = array(
                    "Sender__c" => $senderId,
                    "Recipient__c" => $invite->Id,
                    "Type__c" => "Invite a friend");
                array_push($mailSent, $sObject);   
        // Log messages into
    $results = $client->create($mailSent);
catch (Exception $e) {
    $errorMsg = "We are unable to send invitations at this time.";   

thank you for your suggestions. Basically, the "sendEmail" function is implemented in the salesforce API 9 and thus can be executed by sending a correct piece of XML. So  - with nusoap being capable of forming any XML structure - this has to be somewhat possible.
Did you ever figure out how to accomplish this? I think I am getting close with the following demo function that I added to SforceBaseClient.php but I get the following error:

Must specify a {}type attribute value for the {}messages element

Here is the function so far:

  public function sendEmail() {
    $params = array();
    $params['messages']['bccAddresses'] = new SoapVar('', XSD_STRING, 'string', '');
    $params['messages']['ccAddresses'] = new SoapVar('', XSD_STRING, 'string', '');
    $params['messages']['charset'] = new SoapVar('utf-8', XSD_STRING, 'string', '');
    $params['messages']['htmlBody'] = new SoapVar('howdy', XSD_STRING, 'string', '');
    $params['messages']['plainTextBody'] = new SoapVar('testing 123', XSD_STRING, 'string', '');
    $params['messages']['targetObjectId'] = new SoapVar('', XSD_STRING, 'string', '');
    $params['messages']['toAddresses'] = new SoapVar('', XSD_STRING, 'string', '');
   $this->sforce->__soapCall("sendEmail", array('sendEmail' => $params));