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
HarryBHarryB 

Looking for "sendEmail" example

Hello,
 
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!
 
Cheers,
Harry
HarryBHarryB
Does anyone have a clue?!
 
Cheers,
Harry
ClaiborneClaiborne
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.
 
Code:
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) {
                $messageCount++;                                                 
                $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 saleforce.com
    $results = $client->create($mailSent);
           
}
catch (Exception $e) {
    $errorMsg = "We are unable to send invitations at this time.";   
}

 
HarryBHarryB
David,
 
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.
 
Cheers,
Harry
BRADINOBRADINO
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 {http://www.w3.org/2001/XMLSchema-instance}type attribute value for the {urn:enterprise.soap.sforce.com}messages element


Here is the function so far:

  public function sendEmail() {
   
    $this->_setSessionHeader();
   
    $params = array();
    $params['messages']['bccAddresses'] = new SoapVar('', XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema');
    $params['messages']['ccAddresses'] = new SoapVar('', XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema');
    $params['messages']['charset'] = new SoapVar('utf-8', XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema');
    $params['messages']['htmlBody'] = new SoapVar('howdy', XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema');
    $params['messages']['plainTextBody'] = new SoapVar('testing 123', XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema');
    $params['messages']['targetObjectId'] = new SoapVar('', XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema');
    $params['messages']['toAddresses'] = new SoapVar('info@bradino.com', XSD_STRING, 'string', 'http://www.w3.org/2001/XMLSchema');
   
   $this->sforce->__soapCall("sendEmail", array('sendEmail' => $params));

  }