Swift_Mime_MimePart::setBody PHP Method

setBody() public method

Set the body of this entity, either as a string, or as an instance of {@link Swift_OutputByteStream}.
public setBody ( mixed $body, string $contentType = null, string $charset = null ) : Swift_Mime_MimePart
$body mixed
$contentType string optional
$charset string optional
return Swift_Mime_MimePart
    public function setBody($body, $contentType = null, $charset = null)
    {
        if (isset($charset)) {
            $this->setCharset($charset);
        }
        $body = $this->_convertString($body);
        parent::setBody($body, $contentType);
        return $this;
    }

Usage Example

 public function setPlain($plain)
 {
     if (!isset($this->plainMimePart)) {
         $this->plainMimePart = \Swift_MimePart::newInstance($plain, 'text/plain');
     } else {
         $this->emailObj->detach($this->plainMimePart);
         $this->plainMimePart->setBody($plain);
     }
     if (!empty($plain)) {
         $this->emailObj->attach($this->plainMimePart);
     }
 }