11

メールに添付ファイルを追加したい。私はsfmailerクラスを使用しています。

ここで、以下にコードを示します。

$mail_body = '<p>custom html mail content</p>';
$message = Swift_Message::newInstance('Message title')
  ->setFrom(array('sender'))
  ->setTo(array('receiver'))
  ->setBody($mail_body, 'text/html', 'utf-8');

try {
  $this->getMailer()->send($message);
}
catch(Exception $e) {

}
4

2 に答える 2

31

迅速なメーラーを使用してドキュメントを電子メールに添付するには、いくつかのオプションがあります。

symfonyドキュメントから:

$message = Swift_Message::newInstance()
  ->setFrom('from@example.com')
  ->setTo('to@example.com')
  ->setSubject('Subject')
  ->setBody('Body')
  ->attach(Swift_Attachment::fromPath('/path/to/a/file.zip'))
;

$this->getMailer()->send($message);

そして、他の多くの可能性は、迅速なメーラードキュメントからのものです。

于 2012-06-01T07:51:35.037 に答える