Mailgun\Messages\MessageBuilder::addTag PHP Method

addTag() public method

public addTag ( string $tag )
$tag string
    public function addTag($tag)
    {
        if ($this->counters['attributes']['tag'] < Api::TAG_LIMIT) {
            if (isset($this->message['o:tag'])) {
                array_push($this->message['o:tag'], $tag);
            } else {
                $this->message['o:tag'] = [$tag];
            }
            $this->counters['attributes']['tag'] += 1;
            return $this->message['o:tag'];
        } else {
            throw new TooManyParameters(ExceptionMessages::TOO_MANY_PARAMETERS_TAGS);
        }
    }

Usage Example

示例#1
0
 /**
  * Add Mailgun tags to the message.
  * Tag limit is 3.
  *
  * @param string|array $tags
  *
  * @return \Bogardo\Mailgun\Mail\Message
  */
 public function tag($tags)
 {
     $tags = array_slice((array) $tags, 0, 3);
     foreach ($tags as $tag) {
         $this->messageBuilder->addTag($tag);
     }
     return $this;
 }