Skip to product menu
Skip to main content

PHP SDK Samples - Send Mail Operations

Get Email Addresses
              
              
<?php
namespace com\zoho\crm\sample\sendmail;

use com\zoho\crm\api\sendmail\SendMailOperations;

use com\zoho\crm\api\sendmail\ResponseWrapper;

use com\zoho\crm\api\sendmail\Mail;

use com\zoho\crm\api\inventorytemplates\InventoryTemplate;

use com\zoho\crm\api\sendmail\BodyWrapper;

use com\zoho\crm\api\sendmail\UserAddress;

use com\zoho\crm\api\sendmail\APIException;

use com\zoho\crm\api\sendmail\ActionWrapper;

use com\zoho\crm\api\sendmail\SuccessResponse;

class SendMail
{
    public static function getEmailAddresses()
    {
        //Get instance of SendMailOperations Class
        $sendMailOperations = new SendMailOperations();

        //Call getEmailAddresses method that takes ParameterMap instance as parameter
        $response = $sendMailOperations->getEmailAddresses();

        if($response != null)
        {
            //Get the status code from response
            echo("Status code " . $response->getStatusCode() . "\n");

            if(in_array($response->getStatusCode(), array(204, 304)))
            {
                echo($response->getStatusCode() == 204? "No Content\n" : "Not Modified\n");

                return;
            }

            //Get object from response
            $responseHandler = $response->getObject();

            if($responseHandler instanceof ResponseWrapper)
            {
                //Get the received ResponseWrapper instance
                $responseWrapper = $responseHandler;

                //Get the list of obtained Mail instances
                $emails = $responseWrapper->getFromAddresses();

                foreach($emails as $email)
                {
                    echo("UserName: " . $email->getUserName() . "\n");

                    echo("Mail Type: " . $email->getType() . "\n");

                    echo("Mail : " . $email->getEmail() . "\n");

                    echo("Mail ID: " . $email->getId() . "\n");

                    echo("Mail Default: " . $email->getDefault() . "\n");
                }
            }
            //Check if the request returned an exception
            else if($responseHandler instanceof APIException)
			{
				//Get the received APIException instance
				$exception = $responseHandler;

				//Get the Status
				echo("Status: " . $exception->getStatus()->getValue() . "\n");

				//Get the Code
				echo("Code: " . $exception->getCode()->getValue() . "\n");

				echo("Details: " );

				//Get the details map4
				foreach($exception->getDetails() as $key => $value)
				{
					//Get each value in the map
					echo($key . ": " .$value . "\n");
				}

				//Get the Message
				echo("Message: " . $exception->getMessage()->getValue() . "\n");
			}
        }
    }

}

?>

 
Send Mail