Maileon PHP client  1.5.0
Easily integrate your PHP application with Maileon.
Transaction.php
1 <?php
2 
16  public $type;
17 
23  public $contact;
24 
31  public $import;
32 
38  public $content;
39 
44  public $attachments;
45 
49  function __construct() {
50  $this->content = array();
51  $this->attachments = array();
52  $this->contact = new com_maileon_api_transactions_ContactReference();
58  }
59 
67  function addAttachmentFromFile($filename, $mimetype, $attachmentFileName = null) {
68  $handle = fopen($filename, "rb");
69  if (FALSE === $filename) {
70  throw new com_maileon_api_MaileonAPIException("Cannot read file " . $filename . ".");
71  }
72  $contents = '';
73  while (!feof($handle)) {
74  $contents .= fread($handle, 8192);
75  }
76  fclose($handle);
77  if ($attachmentFileName === null) {
78  $attachmentFileName = basename($filename);
79  }
80  $attachment = new com_maileon_api_transactions_Attachment($attachmentFileName, $mimetype, base64_encode($contents));
81  $this->attachments[] = $attachment;
82  }
83 
90  function addAttachmentFromBinaryData($filename, $mimetype, $contents) {
91  $attachment = new com_maileon_api_transactions_Attachment($filename, $mimetype, base64_encode($contents));
92  $this->attachments[] = $attachment;
93  }
94 
101  function addAttachmentFromBase64Data($filename, $mimetype, $contents) {
102  $attachment = new com_maileon_api_transactions_Attachment($filename, $mimetype, $contents);
103  $this->attachments[] = $attachment;
104  }
105 
110  function toString() {
111  return "Transaction [type=" . $this->type . ", contact=(" . (empty( $this->contact))?"":$this->contact->toString() . "), import=(" . (empty( $this->import))?"":$this->import->toString() . "), content=(" . json_encode($this->content) . ")]";
112  }
113 
114  function toArray() {
115  $array = parent::toArray();
116 
117  if(isset($array['import'])) {
118  unset($array['contact']);
119  //$array['import'] = array( "contact" => $array['import'] );
120  }
121 
122  return $array;
123  }
124 }
addAttachmentFromBase64Data($filename, $mimetype, $contents)
addAttachmentFromFile($filename, $mimetype, $attachmentFileName=null)
Definition: Transaction.php:67
addAttachmentFromBinaryData($filename, $mimetype, $contents)
Definition: Transaction.php:90