Webiny\Component\Mailer\Bridge\SwiftMailer\Message::addAttachment PHP Method

addAttachment() public method

Attach a file to your message.
public addAttachment ( File $file, string $fileName = '', string $type = 'plain/text' )
$file Webiny\Component\Storage\File\File File instance
$fileName string Optional name that will be set for the attachment.
$type string Optional MIME type of the attachment
    public function addAttachment(File $file, $fileName = '', $type = 'plain/text')
    {
        $attachment = new \Swift_Attachment($file->getContents(), $fileName, $type);
        $this->message->attach($attachment);
        return $this;
    }

Usage Example

コード例 #1
0
ファイル: MessageTest.php プロジェクト: Webiny/Framework
 /**
  * @dataProvider messageProvider
  *
  * @param Message $message
  */
 public function testAddAttachment($message)
 {
     $storage = new Storage(new LocalStorageDriver(['Directory' => __DIR__ . '/Attachments']));
     $message->addAttachment(new File('Attachment.yaml', $storage), 'ExampleConfig.yaml', 'text/yaml');
     $children = $message->getChildren();
     $this->assertSame('text/yaml', $children[0]->getContentType());
 }