Last active
December 12, 2015 04:08
-
-
Save EuphoryX1/4711793 to your computer and use it in GitHub Desktop.
\Swift::init ...を入れないとサブジェクトが化けました。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
\Swift::init(function () { | |
\Swift_DependencyContainer::getInstance() | |
->register('mime.qpheaderencoder') | |
->asAliasOf('mime.base64headerencoder'); | |
\Swift_Preferences::getInstance()->setCharset('iso-2022-jp'); | |
}); | |
$message = \Swift_Message::newInstance() | |
->setSubject('長めの日本語サブジェクトを送信した場合の挙動の確認をおこなう') | |
->setFrom(array('[email protected]' => 'スイフトメーラー')) | |
->setTo(array('[email protected]' => 'Symfony2環境')) | |
->setBody("メールが送信されました"); | |
//->setBody($this->renderView('HelloBundle:Hello:email.txt.twig', array('name' => $name))); | |
//文面をテンプレートから生成する場合 | |
// $messageに対するいろいろなメソッドは http://swiftmailer.org/docs/messages.html 参照 | |
if ($this instanceof ContainerAwareCommand) { | |
$container = $this->getContainer(); | |
$mailer = $container->get('mailer'); | |
} else { | |
$mailer = $this->get('mailer'); | |
} | |
$mailer->send($message); | |
if (isset($container)) { | |
// コマンドアプリケーションでspool=memoryの場合は、flushしないとメールが送信されない | |
$spool = $mailer->getTransport()->getSpool(); | |
$transport = $container->get('swiftmailer.transport.real'); | |
$spool->flushQueue($transport); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment